Submission #865772

#TimeUsernameProblemLanguageResultExecution timeMemory
865772RequiemCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
388 ms262144 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,dist1[MAXN],dist2[MAXN]; vector<ii> g[MAXN]; void prep(){ priority_queue<ii,vector<ii>,greater<ii>> pq; pq.push({0,s}); memset(dist1,0x3f,sizeof(dist1)); dist1[s] = 0; while(!pq.empty()){ int u = pq.top().se; int du = pq.top().fi; pq.pop(); if (du > dist1[u]) continue; for(auto pt: g[u]){ int v = pt.fi; int w = pt.se; if (dist1[v] > dist1[u] + w){ dist1[v] = dist1[u] + w; pq.push({dist1[v],v}); } } } memset(dist2,0x3f,sizeof(dist2)); dist2[t] = 0; pq.push({0,t}); while(!pq.empty()){ int u = pq.top().se; int du = pq.top().fi; pq.pop(); if (du > dist2[u]) continue; for(auto pt: g[u]){ int v = pt.fi; int w = pt.se; if (dist2[v] > dist2[u] + w){ dist2[v] = dist2[u] + w; pq.push({dist2[v],v}); } } } } int dist[MAXN]; ii best[MAXN]; void upd(ii &a,ii u){ if (dist[a.se] > dist[u.se]) a = u; } bool onpath(int u,int v,int w){ return (dist1[u] + dist2[v] + w == dist1[t] or dist1[v] + dist2[u] + w == dist1[t]); } struct cmp{ bool operator () (ii a,ii b){ return dist[a.se] > dist[b.se]; } }; vector<ii> storage[MAXN]; void dijk(int s){ priority_queue<ii,vector<ii>,greater<ii>> pq; pq.push({0,s}); memset(dist,0x3f,sizeof(dist)); dist[s] = 0; storage[s].pb({0,s}); while(!pq.empty()){ int u = pq.top().se; int du = pq.top().fi; pq.pop(); if (du > dist[u]) continue; // cout<<u<<' '<<du<<' '<<best[u].fi<<' '<<best[u].se<<endl; for(auto pt: g[u]){ int v = pt.fi; int w = pt.se; for(auto pt: storage[u]){ int mx = pt.se; int dx = pt.fi; if (onpath(u,v,w) and onpath(mx,v,dx + w)){ if (dist[v] > dist[mx]){ dist[v] = dist[mx]; pq.push({dist[v],v}); storage[v].clear(); storage[v].pb({dx + w,mx}); } else { storage[v].pb({dx + w, mx}); } } } if (dist[v] > dist[u] + w){ dist[v] = dist[u] + w; pq.push({dist[v],v}); storage[v].pb({0,v}); } } } cout<<dist[v]<<endl; } 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}); } prep(); dijk(u); }

Compilation message (stderr)

commuter_pass.cpp:117:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  117 | 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...