# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
96939 | 2019-02-12T19:46:58 Z | Kastanda | Cities (BOI16_cities) | C++11 | 6000 ms | 34836 KB |
#include<bits/stdc++.h> using namespace std; const int N = 100005, K = 5; int n, m, k, A[K]; bool M[N]; long long dp[1 << K][N]; vector < pair < int , int > > Adj[N]; int main() { scanf("%d%d%d", &n, &k, &m); memset(dp, 63, sizeof(dp)); for (int i = 0; i < k; i++) scanf("%d", &A[i]), dp[1 << i][A[i]] = 0; for (int i = 1; i <= m; i++) { int v, u, w; scanf("%d%d%d", &v, &u, &w); Adj[v].push_back({u, w}); Adj[u].push_back({v, w}); } for (int mask = 1; mask < (1 << k); mask ++) { if (__builtin_popcount(mask) > 1) for (int v = 1; v <= n; v ++) for (int sub = mask; sub; sub = (sub - 1) & mask) if (sub && (sub ^ mask)) for (auto &u : Adj[v]) if (dp[mask][v] > dp[sub][v] + dp[mask ^ sub][u.first] + u.second) dp[mask][v] = dp[sub][v] + dp[mask ^ sub][u.first] + u.second; queue < int > Pq; memset(M, 0, sizeof(M)); for (int v = 1; v <= n; v ++) Pq.push(v); while (Pq.size()) { int v = Pq.front(); M[v] = 0; Pq.pop(); for (auto &u : Adj[v]) if (dp[mask][u.first] > dp[mask][v] + u.second) { dp[mask][u.first] = dp[mask][v] + u.second; if (!M[u.first]) M[u.first] = 1, Pq.push(u.first); } } } return !printf("%lld\n", dp[(1 << k) - 1][A[0]]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 27740 KB | Output is correct |
2 | Correct | 26 ms | 27768 KB | Output is correct |
3 | Correct | 23 ms | 27748 KB | Output is correct |
4 | Correct | 22 ms | 27776 KB | Output is correct |
5 | Correct | 24 ms | 27840 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 669 ms | 34556 KB | Output is correct |
2 | Correct | 436 ms | 34168 KB | Output is correct |
3 | Execution timed out | 6099 ms | 31380 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 27824 KB | Output is correct |
2 | Correct | 24 ms | 27852 KB | Output is correct |
3 | Correct | 27 ms | 27876 KB | Output is correct |
4 | Correct | 25 ms | 27896 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1314 ms | 34608 KB | Output is correct |
2 | Correct | 1098 ms | 34284 KB | Output is correct |
3 | Execution timed out | 6033 ms | 31372 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2783 ms | 34548 KB | Output is correct |
2 | Correct | 4223 ms | 34836 KB | Output is correct |
3 | Correct | 1974 ms | 34364 KB | Output is correct |
4 | Execution timed out | 6005 ms | 31352 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |