제출 #166977

#제출 시각아이디문제언어결과실행 시간메모리
166977LightningEvacuation plan (IZhO18_plan)C++14
23 / 100
890 ms22040 KiB
#include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <set> #include <map> #include <iomanip> #include <stack> #include <queue> #include <deque> using namespace std; typedef long long ll; typedef pair <int, int> pii; #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define pb push_back #define ppb pop_back #define mkp make_pair #define F first #define S second #define show(a) cerr << #a <<" -> "<< a <<"\n" #define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d)) #define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d)) //#define int ll const int N = 2e5; const int INF = 1e9; int n, m, d[N], k, q; vector <pii> g[N]; set <pii> st; int main () { ios_base::sync_with_stdio(false); // cin.tie(NULL); cin >> n >> m; for(int i = 1; i <= m; ++i) { int a, b, c; cin >> a >> b >> c; g[a].pb(mkp(c, b)); g[b].pb(mkp(c, a)); } for(int i = 1; i <= n; ++i) { d[i] = INF; } cin >> k; fo(i, 1, k, 1) { int b; cin >> b; d[b] = 0; st.insert(mkp(0, b)); } while(sz(st)) { int v = st.begin() -> S; st.erase(st.begin()); for(pii it : g[v]) { int w = it.F; int to = it.S; if(d[to] > d[v] + w) { st.erase(mkp(d[to], to)); d[to] = d[v] + w; st.insert(mkp(d[to], to)); } } } cin >> q; fo(it, 1, q, 1) { int s, t; cin >> s >> t; //show(d[s]); //show(d[t]); cout << min(d[s], d[t]) <<'\n'; } return 0; } /* 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 */
#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...