Submission #865910

#TimeUsernameProblemLanguageResultExecution timeMemory
865910RequiemCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
219 ms46220 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define MOD 1000000007 #define INF 1e18 #define fi first #define se second #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORD(i,a,b) for(int i=a;i>=b;i--) #define sz(a) ((int)(a).size()) #define endl '\n' #define pi 3.14159265359 #define TASKNAME "bus" template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } using namespace std; typedef pair<int,int> ii; typedef pair<int,ii> iii; typedef vector<int> vi; const int MAXN = 2e5 + 9; int n,m,s,t,u,v,distfroms[MAXN],distfromu[MAXN],distfromv[MAXN]; vector<ii> g[MAXN]; set<int> traceback[MAXN]; vector<int> shortestpath[MAXN]; void dijkstra(int start,int dist[]){ for(int i=1;i<=n;i++){ dist[i] = INF; } priority_queue<ii,vector<ii>,greater<ii>> pq; dist[start] = 0; pq.push({0,start}); while(!pq.empty()){ int u = pq.top().se; int du = pq.top().fi; pq.pop(); if (du > dist[u]) continue; for(auto pt: g[u]){ int v = pt.fi; int w = pt.se; if (dist[v] > dist[u] + w){ dist[v] = dist[u] + w; pq.push({dist[v],v}); if (s==start) { traceback[v].clear(); traceback[v].insert(u); } } else if (dist[v] == dist[u] + w){ if (s==start) { traceback[v].insert(u); } } } } } int best1[MAXN],best2[MAXN]; bool visited[MAXN]; main() { fast; // freopen(TASKNAME".inp","r",stdin); // freopen(TASKNAME".out","w",stdout); cin>>n>>m; cin>>s>>t; cin>>u>>v; for(int i=1;i<=m;i++){ int u,v,w; cin>>u>>v>>w; g[u].pb({v,w}); g[v].pb({u,w}); } dijkstra(s,distfroms); dijkstra(u,distfromu); dijkstra(v,distfromv); queue<int> q; q.push(t); visited[t] = true; while (!q.empty()){ int u = q.front(); q.pop(); for(auto v: traceback[u]){ if (!visited[v]){ visited[v] = true; shortestpath[v].pb(u); q.push(v); } } } // for(int i=1;i<=n;i++){ // for(auto x: shortestpath[i]){ // cout<<i<<' '<<x.fi<<endl; // } // cout<<endl; // } q.push(1); int ans = distfromu[v]; memset(best1,0x3f,sizeof(best1)); memset(best2,0x3f,sizeof(best2)); memset(visited,false,sizeof(visited)); while(!q.empty()){ int u = q.front(); q.pop(); best1[u] = min(best1[u], distfromu[u]); best2[u] = min(best2[u], distfromv[u]); ans = min(ans, best1[u] + distfromv[u]); ans = min(ans, best2[u] + distfromu[u]); for(auto v: shortestpath[u]){ best1[v] = min(best1[v],best1[u]); best2[v] = min(best2[v],best2[u]); if (!visited[v]){ visited[v] = true; q.push(v); } } } cout<<ans<<endl; }

Compilation message (stderr)

commuter_pass.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...