# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
96944 | 2019-02-12T19:54:20 Z | Kastanda | Cities (BOI16_cities) | C++11 | 6000 ms | 34876 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; for (int v = 1; v <= n; v ++) Pq.push(v), M[v] = 1; 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 | 24 ms | 27776 KB | Output is correct |
2 | Correct | 23 ms | 27640 KB | Output is correct |
3 | Correct | 25 ms | 27776 KB | Output is correct |
4 | Correct | 23 ms | 27776 KB | Output is correct |
5 | Correct | 24 ms | 27776 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 768 ms | 34628 KB | Output is correct |
2 | Correct | 583 ms | 34152 KB | Output is correct |
3 | Execution timed out | 6047 ms | 31544 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 27776 KB | Output is correct |
2 | Correct | 26 ms | 27748 KB | Output is correct |
3 | Correct | 31 ms | 27796 KB | Output is correct |
4 | Correct | 28 ms | 27768 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1447 ms | 34772 KB | Output is correct |
2 | Correct | 1076 ms | 34220 KB | Output is correct |
3 | Execution timed out | 6064 ms | 31520 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2650 ms | 34772 KB | Output is correct |
2 | Correct | 2766 ms | 34876 KB | Output is correct |
3 | Correct | 2425 ms | 34284 KB | Output is correct |
4 | Execution timed out | 6045 ms | 31508 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |