# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
62050 | 2018-07-27T10:07:28 Z | Crown | Cities (BOI16_cities) | C++14 | 262 ms | 44956 KB |
#include <bits/stdc++.h> using namespace std; #define X first #define Y second #define pb push_back typedef pair<int, int> ii; typedef long long ll; typedef vector<int> vi; typedef vector< ii > vii; const int maxn = 1e5+5; const int maxk = 5; vii adj[maxn]; int n, k, m; int imp[maxk+5]; ll dist[(1<<5)+5][maxn]; int mark[maxn]; struct node { int bit, u; ll d; node(int _bit, int _u, ll _d) { bit = _bit; u = _u; d = _d; } bool operator < (node other) const { return d> other.d; } }; int main() { memset(mark, -1, sizeof mark); scanf("%d %d %d", &n, &k, &m); for(int i = 0; i< k; i++) { scanf("%d", imp+i); mark[imp[i]] = i; } for(int i = 1; i<= m; i++) { int u, v, w; scanf("%d %d %d", &u, &v, &w); adj[u].pb(ii(v, w)); adj[v].pb(ii(u, w)); } memset(dist, 32, sizeof dist); priority_queue<node> pq; for(int i = 1; i<= n; i++) { dist[0][i] = 0; pq.push(node(0, i, 0)); } for(int i = 0; i< k; i++) { dist[1<<i][imp[i]] = 0; pq.push(node(1<<i, imp[i], 0)); } while(!pq.empty()) { node x = pq.top(); pq.pop(); int bit = x.bit, u = x.u; ll d = x.d; if(d> dist[bit][u]) continue; for(auto edge : adj[u]) { int v = edge.X, w = edge.Y; if(d+w < dist[bit][v]) { dist[bit][v] = d+w; for(int comp = 0; comp< (1<<k); comp++) { if(dist[bit|comp][v]> dist[bit][v]+dist[comp][v]) { dist[bit|comp][v] = dist[bit][v]+dist[comp][v]; pq.push(node(bit|comp, v, dist[bit|comp][v])); } } } } } ll best = 1e18; for(int i = 1; i<= n; i++) best = min(best, dist[(1<<k)-1][i]); printf("%lld\n", best); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 31992 KB | Output is correct |
2 | Correct | 31 ms | 32232 KB | Output is correct |
3 | Incorrect | 39 ms | 32232 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 254 ms | 44880 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 44880 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 250 ms | 44956 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 262 ms | 44956 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |