# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
526227 | 2022-02-14T01:46:52 Z | acyme_nom | Cities (BOI16_cities) | C++14 | 130 ms | 208424 KB |
/// acyme_nom /// #include <bits/stdc++.h> using namespace std; #define task "thanh" #define BUG(x) {cout << #x << " = " << x << '\n';} #define PR(x,l,r) {cout << #x << " = "; for(int i=l; i<=r; i++) cout << x[i] << ' '; cout << '\n';} #define MAXN 100011 using ld = long double; using ll = long long; using ii = pair<int,int>; #define X first #define Y second #define int long long int n,m,k; vector <ii> adj[MAXN]; ll dp[1<<7][MAXN]; /// dp[S][i] da di duoc tap S, dang o dinh i void read() { cin >> n >> m >> k; for(int mask=0; mask<(1<<7); mask++) for(int i=1; i<=n; i++) dp[mask][i] = 1e18; for(int i=1; i<=k; i++) { int x; cin >> x; dp[1<<(i-1)][x] = 0; } for(int i=1; i<=m; i++) { int u,v,c; cin >> u >> v >> c; adj[u].push_back(ii(c,v)); adj[v].push_back(ii(c,u)); } } void solve() { for(int mask = 0; mask<(1<<k); mask++) { for(int submask = mask; submask; submask = (submask-1)&mask) { if(submask==mask) continue; for(int i=1; i<=n; i++) { dp[mask][i] = min(dp[mask][i],dp[mask^submask][i] + dp[submask][i]); } } priority_queue <ii,vector<ii>,greater <ii> > pq; for(int i=1; i<=n; i++) { if(dp[mask][i]<1e18) pq.push(ii(dp[mask][i],i)); } while(!pq.empty()) { int u = pq.top().Y; int du = pq.top().X; pq.pop(); if(dp[mask][u]!=du) continue; for(auto e:adj[u]) { if(dp[mask][e.Y]>dp[mask][u]+e.X) { dp[mask][e.Y] = dp[mask][u] + e.X; pq.push(ii(dp[mask][e.Y],e.Y)); } } } } int fullmask = (1<<k)-1; int ans = 1e18; for(int i=1; i<=n; i++) ans = min(ans,dp[fullmask][i]); cout << ans <<'\n'; } int32_t main() { if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL); int t; t = 1; // cin >> t; /// multitest while(t--) { read(); solve(); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 3300 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 122 ms | 208424 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 8 ms | 8520 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 130 ms | 208356 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 122 ms | 208340 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |