# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
27711 | 2017-07-13T14:00:20 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 int n,k,m; int p2[10]; int sp[maxn]; long long mem[maxn][35]; vector<pair<int,int> > can[35]; vector<pair<int,int> > from[maxn]; priority_queue<pair<long long,int> > heap; void mssp(int bit) { int i,x,y; long long val; for(i=1;i<=n;i++) heap.push({-mem[i][bit],i}); while(!heap.empty()) { x = heap.top().second; val = -heap.top().first; heap.pop(); if(val>mem[x][bit]) continue ; for(i=0;i<from[x].size();i++) { y = from[x][i].first; val = from[x][i].second; if(mem[y][bit] > mem[x][bit] + val) { mem[y][bit] = mem[x][bit] + val; heap.push({-mem[y][bit],y}); } } } } main() { int i,j,x,y,val,bit; long long ans; 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,i-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].first] + mem[x][can[bit][i].second]); 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 | 983 ms | 44560 KB | Output is correct |
2 | Correct | 1166 ms | 44488 KB | Output is correct |
3 | Correct | 563 ms | 38384 KB | Output is correct |
4 | Correct | 143 ms | 36644 KB | Output is correct |
5 | Correct | 646 ms | 44552 KB | Output is correct |
6 | Correct | 149 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 | 9 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 | 6 ms | 32236 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2199 ms | 44552 KB | Output is correct |
2 | Correct | 1906 ms | 44344 KB | Output is correct |
3 | Correct | 1333 ms | 38388 KB | Output is correct |
4 | Correct | 1146 ms | 40988 KB | Output is correct |
5 | Correct | 313 ms | 38904 KB | Output is correct |
6 | Correct | 113 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 | - |