# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1027890 | 2024-07-19T10:58:11 Z | hasan2006 | Cities (BOI16_cities) | C++17 | 48 ms | 76892 KB |
#include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define se second #define fi first #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 1e5 + 9 , mod = 1e9 + 7; ll dp[N][40] , c[N] , d[N] , a[N] , b[N] , p[N]; vector<pair<int,int>>v[N]; void solve() { ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ; cin>>n>>k>>m; for(i = 0; i < (1 << k); i++) for(j = 0; j < n; j++) dp[j][i] = 1e18; for(i = 1; i <= k; i++) cin>>x , dp[x - 1][(1 << (i - 1))] = 0; for(i = 1; i <= m; i++){ cin>>l>>r>>x; l-- , r--; v[l].pb({r , x}); v[r].pb({l , x}); } for(i = 1; i < (1 << k); i++){ for(j = 1; j < i; j++){ x = i ^ j; if((j | i) != i || x > j) continue; for(f = 0; f < n; f++) dp[f][i] = min(dp[f][i] , dp[f][j] + dp[f][x]); } priority_queue<pair<int,int>>q; for(j = 0; j < n; j++){ c[j] = 0; if(dp[j][i] < 1e18) q.push({-dp[j][i] , j}); } while(!q.empty()){ x = q.top().second , y = -q.top().first; q.pop(); if(c[x]) continue; c[x] = 1; for(auto to : v[x]){ if(to.se + y < dp[to.fi][i]){ dp[to.fi][i] = to.se + y; q.push({-dp[to.fi][i] , to.fi}); } } } } for(i = 0; i < n; i++) mn = min(mn , dp[i][(1 << k) - 1]); cout<<mn<<"\n"; } int main(){ TL; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ int t = 1; // cin>>t; while(t--) { solve(); } } // Author : حسن
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 31 ms | 76884 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 31 ms | 76884 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 48 ms | 76884 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 32 ms | 76892 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 35 ms | 76880 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |