Submission #1003031

#TimeUsernameProblemLanguageResultExecution timeMemory
1003031tamir1Commuter Pass (JOI18_commuter_pass)C++17
15 / 100
227 ms35276 KiB
#include<bits/stdc++.h> #define ll long long #define ff first #define ss second using namespace std; ll n,m,s,t,u,v,x,y,z,i,dis[100001]; vector<pair<ll,ll>> g[100001]; priority_queue<pair<ll,ll>> q; map<pair<ll,ll>,bool> mp; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> m >> s >> t >> u >> v; for(i=1;i<=m;i++){ cin >> x >> y >> z; g[x].push_back({y,z}); g[y].push_back({x,z}); } memset(dis,-1,sizeof dis); q.push({0,s}); while(!q.empty()){ z=q.top().ff; x=q.top().ss; q.pop(); if(dis[x]!=-1) continue; dis[x]=-z; for(pair<ll,ll> i:g[x]){ if(dis[i.ff]==-1) q.push({z-i.ss,i.ff}); } } x=t; while(x!=s){ for(pair<ll,ll> i:g[x]){ if(dis[x]==dis[i.ff]+i.ss){ mp[{x,i.ff}]=1; mp[{i.ff,x}]=1; x=i.ff; break; } } } memset(dis,-1,sizeof dis); q.push({0,u}); while(!q.empty()){ z=q.top().ff; x=q.top().ss; q.pop(); if(dis[x]!=-1) continue; dis[x]=-z; for(pair<ll,ll> i:g[x]){ if(dis[i.ff]==-1){ if(mp[{x,i.ff}]) q.push({z,i.ff}); else q.push({z-i.ss,i.ff}); } } } cout << dis[v]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...