# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134661 | 2019-07-23T06:41:44 Z | 이온조(#3239) | Telegraph (JOI16_telegraph) | C++14 | 3 ms | 376 KB |
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL * 1e18; long long P[100009], D[100009]; int N, A[100009], C[100009], s; void go(int x, int msk) { if(msk == (1 << N) - 1 && A[x] == s) { puts("0"); exit(0); } P[msk] = C[x]; if(msk & (1 << (A[x]-1))) return; go(A[x], msk | (1 << (A[x]-1))); } int main() { scanf("%d",&N); for(int i=1; i<=N; i++) scanf("%d%d",&A[i],&C[i]); for(int i=0; i<(1<<N); i++) P[i] = INF; for(int i=1; i<=N; i++) { s = i; go(i, (1 << (i-1))); } D[0] = 0; for(int i=1; i<(1<<N); i++) { D[i] = INF; for(int j=i; j>0; j=((j-1)&i)) { D[i] = min(D[i], P[j] + D[i^j]); } } printf("%lld", D[(1<<N) - 1]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |