Submission #667851

#TimeUsernameProblemLanguageResultExecution timeMemory
667851Kaztaev_AlisherEvacuation plan (IZhO18_plan)C++17
12 / 100
1 ms468 KiB
//#pragma GCC optomize ("Ofast") //#pragma GCC optomize ("unroll-loops") //#pragma GCC target ("avx,avx2,fma") #include <bits/stdc++.h> #define F first #define S second #define pb push_back #define sz size #define cl clear #define ins insert #define ers erase #define pii pair < int , int > #define pll pair< long long , long long > #define all(x) x.begin() , x.end() #define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define tostr(x) to_string(x) #define tonum(s) atoi(s.c_str()) #define seon(x) setprecision(x) #define bpop(x) __builtin_popcount(x) #define deb(x) cerr << #x << " = " << x << endl; #define int ll typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; const double PI = 3.14159265; const ll N = 20; const ll mod = 1e9+7; const ll inf = 1e9; const ll INF = 1e18; using namespace std; ll n , m , q; ll dp[N]; vector<pll> g[N]; void bfs(){ set<pll> st; int k; cin >> k; for(int i = 1; i <= n; i++) dp[i] = inf; for(int i = 1; i <= k; i++) { int u; cin >> u; dp[u] = 0; st.ins({0 , u}); } while(st.sz()){ int v = st.begin()->S; st.ers(st.begin()); for(pii to : g[v]){ if(dp[to.F] > dp[v]+to.S){ st.ers({dp[to.F] , to.F}); dp[to.F] = dp[v]+to.S; st.ins({dp[to.F] , to.F}); } } } } ll road[N][N]; void solve(){ cin >> n >> m; for(int i = 1; i <= m; i++){ int a, b , c; cin >> a>> b >> c; g[a].pb({b , c}); g[b].pb({a , c}); } bfs(); if(n <= 15){ cin >> q; for(int i = 1; i <= n; i++){ road[i][i] = dp[i]; set<pll> st; st.ins({road[i][i] , i}); while(st.sz()){ pll v = *st.begin(); st.ers(st.begin()); for(pll to : g[v.S]){ if(road[i][to.F] < min(road[i][v.S] , dp[to.F])){ st.ers({road[i][to.F] , to.F}); road[i][to.F] = min(road[i][v.S] , dp[to.F]); st.ins({road[i][to.F] , to.F}); } } } } while(q--){ int u , v; cin >> u >> v; cout << road[u][v] <<"\n"; } } else { cin >> q; while(q--){ int u , v; cin >> u >> v; cout << min(dp[v] , dp[u]) <<"\n"; } } } signed main(){ ios; solve(); 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...