# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647555 | 2022-10-03T07:17:00 Z | ToroTN | Cities (BOI16_cities) | C++14 | 6000 ms | 43820 KB |
#include<bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define X first #define Y second ll n,k,m,node[5],u_i,v_i,w_i,d[32][100005],u,num,dp[32],pow_2[5],mn=1e18; vector<pair<ll,ll> > g[100005]; vector<ll> bit[6]; priority_queue<pair<ll,ll> > pq; void dij(ll arr[]) { for(int i=1;i<=n;i++) { pq.push({-arr[i],i}); } while(!pq.empty()) { u=pq.top().second; pq.pop(); for(auto [y,cost]:g[u]) { if(arr[u]+cost<arr[y]) { arr[y]=arr[u]+cost; pq.push({-arr[y],y}); } } } } int main() { pow_2[0]=1; for(int i=1;i<=4;i++) { pow_2[i]=pow_2[i-1]*2; } scanf("%lld%lld%lld",&n,&num,&m); for(int i=1;i<=num;i++) { scanf("%lld",&node[i-1]); } for(int i=1;i<=m;i++) { scanf("%lld%lld%lld",&u_i,&v_i,&w_i); g[u_i].pb({v_i,w_i}); g[v_i].pb({u_i,w_i}); } for(int i=0;i<32;i++) { for(int j=1;j<=n;j++) { d[i][j]=1e18; } } for(int i=0;i<num;i++) { d[pow_2[i]][node[i]]=0; dij(d[pow_2[i]]); } for(int i=0;i<32;i++) { ll kmp=0; for(int j=0;j<=4;j++) { if((i|pow_2[j])==i)++kmp; } bit[kmp].pb(i); } // for(int i=1;i<=n;i++) // { // printf("%lld ",d[1][i]); // } // printf("\n"); for(int i=2;i<=num;i++) { for(int j=1;j<=i/2;j++) { for(auto k:bit[i-j]) { for(auto l:bit[j]) { if(k!=l) { for(int c=1;c<=n;c++) { d[(k|l)][c]=d[k][c]+d[l][c]; } dij(d[(k|l)]); } } } } } for(int i=1;i<=n;i++) { mn=min(mn,d[pow_2[num]-1][i]); } printf("%lld\n",mn); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2772 KB | Output is correct |
2 | Correct | 2 ms | 2772 KB | Output is correct |
3 | Correct | 2 ms | 2772 KB | Output is correct |
4 | Incorrect | 2 ms | 2792 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4003 ms | 43744 KB | Output is correct |
2 | Correct | 4205 ms | 42804 KB | Output is correct |
3 | Correct | 2649 ms | 35808 KB | Output is correct |
4 | Correct | 173 ms | 13392 KB | Output is correct |
5 | Correct | 936 ms | 43768 KB | Output is correct |
6 | Correct | 88 ms | 13240 KB | Output is correct |
7 | Correct | 16 ms | 3284 KB | Output is correct |
8 | Correct | 5 ms | 3188 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 55 ms | 3284 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 6095 ms | 43820 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 6032 ms | 43752 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |