結果
問題 | No.19 ステージの選択 |
ユーザー | LayCurse |
提出日時 | 2014-11-07 10:09:29 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 2,649 bytes |
コンパイル時間 | 1,158 ms |
コンパイル使用メモリ | 161,764 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-02 12:27:36 |
合計ジャッジ時間 | 1,867 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 1 ms
6,944 KB |
testcase_16 | AC | 1 ms
6,944 KB |
testcase_17 | AC | 1 ms
6,944 KB |
testcase_18 | AC | 1 ms
6,944 KB |
testcase_19 | AC | 1 ms
6,940 KB |
testcase_20 | AC | 1 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 1 ms
6,944 KB |
testcase_23 | AC | 2 ms
6,940 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) #define mygc(c) (c)=getchar_unlocked() #define mypc(c) putchar_unlocked(c) #define ll long long #define ull unsigned ll void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(int *x, int *y){reader(x);reader(y);} void* setDirectEdge(int N, int M, int A[], int B[], int **es, int ***edge, void *workMemory){int i;*es=(int*)workMemory;*edge=(int**)((*es)+N);(*edge)[0]=(int*)((*edge)+N);rep(i,N)(*es)[i]=0;rep(i,M)(*es)[A[i]]++;REP(i,1,N)(*edge)[i]=(*edge)[i-1]+(*es)[i-1];workMemory=(void*)((*edge)[N-1]+(*es)[N-1]);rep(i,N)(*es)[i]=0;rep(i,M)(*edge)[A[i]][(*es)[A[i]]++]=B[i];return workMemory;} void* getReverseGraph(int N, int *es, int **edge, int **r_es, int ***r_edge, void *workMemory){int i,j,k;*r_es=(int*)workMemory;*r_edge=(int**)((*r_es)+N);(*r_edge)[0]=(int*)((*r_edge)+N);rep(i,N)(*r_es)[i] = 0;rep(i,N)rep(j,es[i])(*r_es)[edge[i][j]]++;REP(i,1,N)(*r_edge)[i]=(*r_edge)[i-1]+(*r_es)[i-1];workMemory=(void*)((*r_edge)[N-1]+(*r_es)[N-1]);rep(i,N)(*r_es)[i]=0;rep(i,N)rep(j,es[i])k=edge[i][j],(*r_edge)[k][(*r_es)[k]++]=i;return workMemory;} int StronglyConnectedComponentsDFS(int *es, int **edge, int num[], int st, int mx){int i,j;num[st]=-2;rep(i,es[st]){j=edge[st][i];if(num[j]==-1)mx=StronglyConnectedComponentsDFS(es,edge,num,j,mx);}num[st]=mx;return mx+1;} int StronglyConnectedComponents(int N, int *es, int **edge, int res[], void *workMemory){int i,j,k,t=0,*s,**e,*q,z,*n,*r;workMemory=getReverseGraph(N,es,edge,&s,&e,workMemory);q=(int*)workMemory;n=q+N;r=n+N;rep(i,N)res[i]=n[i]=-1;k=0;rep(i,N)if(n[i]==-1)k=StronglyConnectedComponentsDFS(es,edge,n,i,k);rep(i,N)r[n[i]]=i;for(k=N-1;k>=0;k--){i=r[k];if(res[i]>=0)continue;res[i]=t;z=0;q[z++]=i;while(z){i=q[--z];rep(j,s[i])if(res[e[i][j]]==-1)res[e[i][j]]=t,q[z++]=e[i][j];}t++;}return t;} int N; int A[222], B[222], L[222]; int com[222], deg[222], mn[222]; int main(){ int i, j, k, nn; int res; int *es, **edge; void *mem = malloc(10000000); reader(&N); rep(i,N) reader(L+i,A+i), A[i]--, B[i]=i; mem = setDirectEdge(N, N, A, B, &es, &edge, mem); nn = StronglyConnectedComponents(N, es, edge, com, mem); res = 0; rep(i,N) res += L[i]; rep(i,N) if(com[A[i]] != com[B[i]]) deg[com[B[i]]]++; rep(i,nn) mn[i] = 10000; rep(i,N) mn[com[i]] = min(mn[com[i]], L[i]); rep(i,nn) if(!deg[i]) res += mn[i]; printf("%.1f\n",res/2.0); return 0; }