# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
27708 | 2017-07-13T13:54:48 Z | top34051 | Cities (BOI16_cities) | C++14 | 4000 ms | 41488 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<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); 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 | Execution timed out | 4000 ms | 41488 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 103 ms | 32236 KB | Output is correct |
2 | Correct | 23 ms | 32236 KB | Output is correct |
3 | Correct | 49 ms | 32244 KB | Output is correct |
4 | Correct | 56 ms | 32236 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 4000 ms | 41480 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 4000 ms | 41484 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |