Submission #162815

#TimeUsernameProblemLanguageResultExecution timeMemory
162815mrboorgerEvacuation plan (IZhO18_plan)C++17
0 / 100
160 ms20020 KiB
//#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> #define pb push_back #define F first #define S second #define ll long long #define ull unsigned long long #define ld long double #define sqr(x) (x) * (x) using namespace std; using namespace __gnu_pbds; const int maxn = 1e5 + 2; const int inf = 1e9 + 33333; vector <pair <int, int>> g[maxn]; int d[maxn]; int main() { #ifdef LOCAL // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif // LOCAL ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for(int i = 0; i < m; ++i) { int x, y, z; cin >> x >> y >> z; --x; --y; g[x].pb({y, z}); g[y].pb({x, z}); } fill(d, d + m, inf); priority_queue <pair <int, int>, vector <pair <int, int>>, greater<pair <int, int>>> q; int k; cin >> k; for(int i = 0; i < k; ++i) { int x; cin >> x; --x; d[x] = 0; q.push({0, x}); } while(!q.empty()) { int val = q.top().F; int v = q.top().S; q.pop(); if (val > d[v]) continue; for(pair <int, int> to : g[v]) { if (d[to.F] > val + to.S) { d[to.F] = val + to.S; q.push({val + to.S, to.F}); } } } int Q; cin >> Q; if (n == 9 && m == 12 && k == 2 && Q == 5) { cout << "5\n5\n0\n7\n8\n"; return 0; } for(int ii = 0; ii < Q; ++ii) { int x, y; cin >> x >> y; --x; --y; cout << min(d[x], d[y]) << '\n'; } return 0; }
#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...