tjut 5934

来源:互联网 发布:安卓程序员待遇 编辑:程序博客网 时间:2024/06/04 23:19
#include <bits/stdc++.h>using namespace std;typedef __int64 LL;typedef pair<LL, LL> PLL;const int MAXN = 1000 + 5;int T, cas, N;struct QNode {    LL x, y, r, c, id;} q[MAXN];vector<int> G[MAXN];int In[MAXN]; // 入度int Low[MAXN], DFN[MAXN], Stack[MAXN], Belong[MAXN]; //Belong数组的值是1~sccint Index, top;int scc;//强连通分量的个数bool Instack[MAXN];int num[MAXN];//各个强连通分量包含点的个数,数组编号1~sccLL w[MAXN]; // 联通分量中最小值void Tarjan(int u) {    int v, sz = G[u].size();    Low[u] = DFN[u] = ++Index;    Stack[top++] = u;    Instack[u] = true;    for(int i = 0; i < sz; i++) {        v = G[u][i];        if(!DFN[v]) {            Tarjan(v);            if( Low[u] > Low[v] )Low[u] = Low[v];        } else if(Instack[v] && Low[u] > DFN[v])            Low[u] = DFN[v];    }    if(Low[u] == DFN[u]) {        scc++;        do {            v = Stack[--top];            Instack[v] = false;            Belong[v] = scc;            num[scc]++;        } while( v != u);    }}void work() {    memset(DFN, 0, sizeof(DFN));    memset(Instack, false, sizeof(Instack));    memset(num, 0, sizeof(num));    memset(In, 0, sizeof(In));    Index = scc = top = 0;    for(int i = 1; i <= N; i++)        if(!DFN[i])            Tarjan(i);    memset(w, 0x3f, sizeof(w));    for(int u = 1; u <= N; u++) {        int x = Belong[u], y, v, sz = G[u].size();;        w[x] = min(w[x], q[u].c);        for(int j = 0; j < sz; j++) {            v = G[u][j], y = Belong[v];            if(x == y) continue;            In[y] ++;        }    }}inline bool IsInter(QNode& a, QNode& b) {    LL dist = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);    return dist <= a.r * a.r;}int main() {    scanf("%d", &T); cas = 0;    while(T --) {        scanf("%d", &N);        for(int i = 1; i <= N; i++) {            scanf("%I64d %I64d %I64d %I64d", &q[i].x, &q[i].y, &q[i].r, &q[i].c);        }        for(int i = 1; i <= N; i++) {            G[i].clear();            for(int j = 1; j <= N; j++) {                if (j == i) continue;                if(IsInter(q[i], q[j])) {                    G[i].push_back(j);                }            }        }        work();        LL ans = 0;        for(int i = 1; i <= scc; i++) {            if(In[i] == 0) {                ans += w[i];            }        }        printf("Case #%d: %I64d\n", ++cas, ans);    }    return 0;}

0 0
原创粉丝点击