Submission #781302

#TimeUsernameProblemLanguageResultExecution timeMemory
781302CookieCities (BOI16_cities)C++14
100 / 100
2494 ms49284 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; ifstream fin("VNOICUP.INP"); ofstream fout("VNOICUP.OUT"); #define sz(a) (int)a.size() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> const ld PI = 3.14159265359; using u128 = __uint128_t; //const int x[4] = {1, -1, 0, 0}; //const int y[4] = {0, 0, 1, -1}; const ll mod = 998244353; const int mxn = 1e5 + 5, mxq = 2e5 + 5, sq = 400, mxv = 2e7 + 5; //const int base = (1 << 18); const ll inf = 1e17, neg = -69420; int n, k, m; int to[mxn + 1]; vt<pll>adj[mxn + 1]; ll dp[mxn + 1][(1 << 5)]; void input(){ cin >> n >> k >> m; for(int i = 1; i <= n; i++)to[i] = -1; for(int i = 0; i < k; i++){ int x; cin >> x; to[x] = i; } for(int i = 0; i < m; i++){ int u, v, w; cin >> u >> v >> w; adj[u].pb({v, w}); adj[v].pb({u, w}); } } /* 4 3 6 1 3 4 1 2 4 1 3 9 1 4 6 2 3 2 2 4 5 3 4 8 */ void process(){ for(int i = 1; i <= n; i++){ for(int j = 0; j < (1 << k); j++){ dp[i][j] = inf; } } for(int i = 1; i <= n; i++){ if(to[i] != -1){ dp[i][(1 << to[i])] = 0; } dp[i][0] = 0; } for(int i = 1; i < (1 << k); i++){ priority_queue<pll, vt<pll>, greater<pll>>pq; for(int j = 1; j <= n; j++){ for(int l = 0;l < i; l++){ if((i | l) == i)dp[j][i] = min(dp[j][i], dp[j][i ^ l] + dp[j][l]); } if(dp[j][i] != inf){ pq.push(make_pair(dp[j][i], j)); } } while(!pq.empty()){ auto [dd, u] = pq.top(); pq.pop(); if(dp[u][i] != dd)continue; for(auto [v, w]: adj[u]){ if(dp[v][i] > dp[u][i] + w){ dp[v][i] = dp[u][i] + w; pq.push({dp[v][i], v}); } } } } ll ans = inf; for(int i = 1; i <= n; i++){ ans = min(ans, dp[i][(1 << k) - 1]); } cout << ans; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); input(); process(); //solve(); return(0); }

Compilation message (stderr)

cities.cpp: In function 'void process()':
cities.cpp:75:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   75 |             auto [dd, u] = pq.top(); pq.pop();
      |                  ^
cities.cpp:77:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   77 |             for(auto [v, w]: adj[u]){
      |                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...