Submission #945710

#TimeUsernameProblemLanguageResultExecution timeMemory
945710ezzzayCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
336 ms262144 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define pb push_back const int N=3e5+5; vector<pair<int,int>>v[N]; set<int>st[N]; int dist[N]; int tmp[N]; int par[N]; bool vis[N]; vector<pair<int,int>>vc; void dfs(int a){ vis[a]=1; for(auto p:v[a]){ int b=p.ff; int c=p.ss; if(vis[b]==0 and dist[b]+c==dist[a])dfs(b); } } signed main(){ int n,m,s,t,x,y; cin>>n>>m>>s>>t>>x>>y; for(int i=0;i<m;i++){ int a,b,c; cin>>a>>b>>c; v[a].pb({b,c}); v[b].pb({a,c}); } for(int i=1;i<=n;i++){ dist[i]=1e16; } priority_queue<pair<int,int>>q; q.push({0,s}); par[s]=s; dist[s]=0; vis[s]=1; while(!q.empty()){ int w=-q.top().ff; int a=q.top().ss; q.pop(); if(dist[a]<w)continue; for(auto p:v[a]){ int b=p.ff; int c=p.ss; st[b].insert(b); if(dist[a]+c<=dist[b]){ dist[b]=dist[a]+c; par[b]=a; q.push({-dist[b],b}); } } } dfs(t); cout<<2; return 0; for(int i=1;i<=n;i++){ dist[i]=1e16; } s=y; q.push({0,s}); par[s]=s; dist[s]=0; while(!q.empty()){ int w=-q.top().ff; int a=q.top().ss; q.pop(); if(dist[a]<w)continue; for(auto p:v[a]){ int b=p.ff; int c=p.ss; if(dist[a]+c<dist[b]){ dist[b]=dist[a]+c; par[b]=a; q.push({-dist[b],b}); } } } int ans=INT_MAX; for(int i=1;i<=n;i++){ if(vis[i]){ ans=min(ans,dist[i]); } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...