# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
27706 | 2017-07-13T13:51:22 Z | top34051 | Cities (BOI16_cities) | C++14 | 4000 ms | 44560 KB |
#include<bits/stdc++.h> using namespace std; #define maxn 100005 #define inf (long long)1e16 struct node { int x; long long val; node(int _x = 0,long long _val = 0) { x = _x; val = _val; } bool operator < (node a) const { return a.val<val; } }; int n,k,m; int p2[10]; int sp[maxn]; long long mem[maxn][35]; vector<int> can[35]; vector<pair<int,int> > from[maxn]; priority_queue<node> heap; void mssp(int bit) { int i,y,val; node t; for(i=1;i<=n;i++) heap.push(node(i,mem[i][bit])); while(!heap.empty()) { t = heap.top(); heap.pop(); if(t.val>mem[t.x][bit]) continue ; for(i=0;i<from[t.x].size();i++) { y = from[t.x][i].first; val = from[t.x][i].second; if(mem[y][bit] > mem[t.x][bit] + val) { mem[y][bit] = mem[t.x][bit] + val; heap.push(node(y,mem[y][bit])); } } } } main() { int i,j,x,y,val,bit; long long ans; node t; scanf("%d%d%d",&n,&k,&m); for(i=1;i<=n;i++) sp[i] = -1; for(i=0;i<k;i++) scanf("%d",&x), sp[x] = i; while(m--) { scanf("%d%d%d",&x,&y,&val); from[x].push_back({y,val}); from[y].push_back({x,val}); } p2[-1] = 0; p2[0] = 1; for(i=1;i<=k;i++) p2[i] = p2[i-1]*2; for(i=0;i<p2[k];i++) for(j=0;j<p2[k];j++) if(((i&j)==j) && i>=j) can[i].push_back(j); for(x=1;x<=n;x++) { for(bit=0;bit<p2[k];bit++) mem[x][bit] = inf; mem[x][p2[sp[x]]] = 0; } for(bit=0;bit<p2[k];bit++) { for(x=1;x<=n;x++) for(i=0;i<can[bit].size();i++) mem[x][bit] = min(mem[x][bit],mem[x][can[bit][i]] + mem[x][bit^can[bit][i]]); mssp(bit); } ans = inf; for(i=1;i<=n;i++) ans = min(ans,mem[i][p2[k]-1]); printf("%lld",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 32104 KB | Output is correct |
2 | Correct | 0 ms | 32104 KB | Output is correct |
3 | Correct | 0 ms | 32104 KB | Output is correct |
4 | Correct | 0 ms | 32104 KB | Output is correct |
5 | Correct | 0 ms | 32104 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1259 ms | 44560 KB | Output is correct |
2 | Correct | 966 ms | 44488 KB | Output is correct |
3 | Correct | 829 ms | 38384 KB | Output is correct |
4 | Correct | 153 ms | 36644 KB | Output is correct |
5 | Correct | 749 ms | 44552 KB | Output is correct |
6 | Correct | 123 ms | 36732 KB | Output is correct |
7 | Correct | 3 ms | 32236 KB | Output is correct |
8 | Correct | 3 ms | 32236 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 32236 KB | Output is correct |
2 | Correct | 6 ms | 32236 KB | Output is correct |
3 | Correct | 3 ms | 32244 KB | Output is correct |
4 | Correct | 3 ms | 32236 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2526 ms | 44552 KB | Output is correct |
2 | Correct | 1996 ms | 44344 KB | Output is correct |
3 | Correct | 989 ms | 38388 KB | Output is correct |
4 | Correct | 876 ms | 40988 KB | Output is correct |
5 | Correct | 276 ms | 38904 KB | Output is correct |
6 | Correct | 156 ms | 38396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 4000 ms | 44556 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |