Submission #628252

#TimeUsernameProblemLanguageResultExecution timeMemory
628252duytuandao21Toll (BOI17_toll)C++17
8 / 100
3089 ms51928 KiB
#include<iostream> #include<cmath> #include<algorithm> #include<stack> #include<queue> #include<deque> using namespace std; #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define fi first #define se second #define ll long long #define mp make_pair #define pb push_back #define ii pair<ll, int> #define task "test" const int inf = 1e9 + 7; const ll infll = (ll)1e18 + 7; const int MOD = 1e9 + 7; const int N = 2e6 + 3; template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;} template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;} int k,n,m,q; vector<ii> adj[N]; void solve(int x,int y) { vector<ll> d(n+1, inf); d[x] = 0; priority_queue< ii, vector<ii>, greater<ii> > p; p.push(mp(0,x)); while(!p.empty()) { int u = p.top().se; int val = p.top().fi; p.pop(); if(val != d[u]) continue; for(ii X : adj[u]) { int v = X.se; int he = X.fi; if(d[v] > val + he) { d[v] = val + he; p.push(mp(d[v], v)); } } } if(d[y] == inf) cout<<-1<<'\n'; else cout<<d[y]<<'\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>k>>n>>m>>q; for(int i=1;i<=m;i++) { int u,v,w; cin>>u>>v>>w; adj[u].pb(mp(w,v)); //adj[v].pb(mp(w,u)); } while(q--) { int u,v; cin>>u>>v; solve(u,v); } 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...