Submission #571528

#TimeUsernameProblemLanguageResultExecution timeMemory
571528vbeeEvacuation plan (IZhO18_plan)C++14
12 / 100
394 ms36924 KiB
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define ii pair<int,int> #define vii vector<ii> #define vi vector<int> #define fi first #define se second #define TASK "evacuationplan" #define ll long long #define pll pair<ll, ll> #define vll vector<ll> #define vpll vector<pll> #define pb push_back #define MASK(i) (1 << (i)) #define BIT(x, i) ((x >> (i)) & 1) using namespace std; const int oo = 1e9 + 7; const ll loo = (ll)1e18 + 7; const int N = 1e5 + 7; const int M = 1e3 + 7; const int LOG = 15; int n, m, k, q, adist[M][M], f[MASK(LOG)][16], minidist[N], ans[16][16]; vector<pair<int, int> > g[N]; vector<int> npp; void minimize(int &a, int b){ if (a > b) a = b; } void apsp(int i){ minidist[i] = oo; for (int j = 1; j <= n; j++) adist[i][j] = oo; adist[i][i] = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> kew; kew.push({0, i}); while (!kew.empty()){ auto k = kew.top(); kew.pop(); if (k.fi > adist[i][k.se]){ continue; } for (auto u : g[k.se]) { if (k.fi + u.se < adist[i][u.fi]){ adist[i][u.fi] = k.fi + u.se; kew.push({k.fi + u.se, u.fi}); } } } for (auto u : npp) minidist[i] = min(minidist[i], adist[i][u]); return; } vector<pair<int, int> > queries; // bool check(int s, int t, int x){ // queue<int> kew; // } int main() { ios_base::sync_with_stdio(0); cin.tie(0); // freopen(TASK".inp", "r", stdin); // freopen(TASK".out", "w", stdout); cin >> n >> m; map<pair<int, int>, bool> checkexist; for (int i = 1; i <= m; i++){ int u, v, w; cin >> u >> v >> w; g[u].pb({v, w}); g[v].pb({u, w}); checkexist[{u, v}] = checkexist[{v, u}] = true; } cin >> k; for (int i = 1; i <= k; i++) { int x; cin >> x; npp.pb(x); } bool sub12 = true; cin >> q; while (q--){ int x, y; cin >> x >> y; queries.pb({x, y}); if (!checkexist[{x, y}]) sub12 = false; } if (n <= 1000 && m <= 1000 && q <= 1000 && sub12){ for (int i = 1; i <= n; i++) apsp(i); for (int j = 0; j < queries.size(); j++) { int x = queries[j].fi, y = queries[j].se; int res = oo; for (int i = 0; i < (int)npp.size(); i++){ res = min({res, adist[x][npp[i]], adist[y][npp[i]]}); } cout << res << "\n"; } } if (n <= 15 && m <= 200 && q <= 200){ for (int i = 1; i <= n; i++) apsp(i); for (int sta = 0; sta < n; sta++){ for (int mask = 0; mask < MASK(n); mask++) for (int j = 0; j < n; j++) f[mask][j] = oo; f[MASK(sta)][sta] = minidist[sta + 1]; for (int mask = 0; mask < MASK(n); mask++){ for (int i = 0; i < n; i++) if (f[mask][i] != oo){ int id = i + 1; for (auto u : g[id]){ int cur = u.fi - 1; if (!BIT(mask, cur)){ minimize(f[mask | MASK(cur)][cur], min(f[mask][i], minidist[u.fi])); } } } } for (int mask = 0; mask < MASK(n); mask++){ for (int i = 0; i < n; i++) if (f[mask][i] != oo){ ans[sta + 1][i + 1] = max(ans[sta + 1][i + 1], f[mask][i]); } } } for (auto u : queries){ cout << ans[u.fi][u.se] << "\n"; } } return 0; }

Compilation message (stderr)

plan.cpp: In function 'int main()':
plan.cpp:88:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |   for (int j = 0; j < queries.size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~~
#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...