Submission #865764

#TimeUsernameProblemLanguageResultExecution timeMemory
865764RequiemCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
254 ms29700 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]); } void dijk(int s){ priority_queue<ii,vector<ii>,greater<ii>> pq; pq.push({0,s}); memset(dist,0x3f,sizeof(dist)); dist[s] = 0; best[s] = {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; int dx = best[u].fi; //khoang k den k1 int mx = best[u].se; //mx la dinh bat dau // if (onpath(u,v,w)) cout<<u<<' '<<v<<' '<<w<<endl; if (onpath(u,v,w) and onpath(best[u].se,v,best[u].fi + w)){ if (dist[v] > dist[best[u].se]){ dist[v] = dist[best[u].se]; pq.push({dist[v],v}); best[v] = {best[u].fi + w,best[u].se}; } } if (dist[v] > dist[u] + w){ dist[v] = dist[u] + w; best[v] = {0,v}; pq.push({dist[v],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: In function 'void dijk(long long int)':
commuter_pass.cpp:85:17: warning: unused variable 'dx' [-Wunused-variable]
   85 |             int dx = best[u].fi; //khoang k den k1
      |                 ^~
commuter_pass.cpp:86:17: warning: unused variable 'mx' [-Wunused-variable]
   86 |             int mx = best[u].se; //mx la dinh bat dau
      |                 ^~
commuter_pass.cpp: At global scope:
commuter_pass.cpp:104:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  104 | 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...