제출 #343646

#제출 시각아이디문제언어결과실행 시간메모리
343646SprdaloEvacuation plan (IZhO18_plan)C++17
0 / 100
186 ms18628 KiB
#include <bits/stdc++.h> using namespace std; #define int ll typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<double> vd; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<string> vs; typedef vector<pi> vp; typedef vector<pl> vpl; const int maxn = 1e5+5; vp e[maxn]; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); int n, m; cin >> n >> m; for (int i = 0; i < m; ++i){ int u, v, w; cin >> u >> v >> w; e[u].push_back({v, w}); e[v].push_back({u, w}); } int k; cin >> k; queue<int> q; vi vis(n+1,0), d(n+1,INT64_MAX/10); for (int i = 0; i < k; ++i){ int x; cin >> x; q.push(x); vis[x] = 1; d[x] = 0; } while(!q.empty()){ int c = q.front(); q.pop(); for (pi p : e[c]){ d[p.first] = min(d[p.first], d[c] + p.second); if (!vis[p.first]){ vis[p.first] = 1; q.push(p.first); } } } int Q; cin >> Q; for (int i = 0; i < Q; ++i){ int u, v; cin >> u >> v; cout << min(d[u], d[v]) << '\n'; } } /* 9 12 1 9 4 1 2 5 2 3 7 2 4 3 4 3 6 3 6 4 8 7 10 6 7 5 5 8 1 9 5 7 5 4 12 6 8 2 2 4 7 5 1 6 5 3 4 8 5 8 1 5 */
#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...