Submission #66820

#TimeUsernameProblemLanguageResultExecution timeMemory
66820MrTEKCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
972 ms33272 KiB
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define len(a) (int)a.size() #define fi first #define sc second #define d1(w) cerr<<#w<<":"<<w<<endl; #define d2(w,c) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<endl; #define d3(w,c,z) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<" "<<#z<<":"<<z<<endl; #define left ind+ind #define right ind+ind+1 #define mid (l+r)/2 #define FAST_IO ios_base::sync_with_stdio(false); #define endl '\n' const int maxn = 620; const long long LINF = 1e18; const int LOG = 31; const int INF = 1e9; const int N = 1e5 + 5; const int M = 1e4 + 5; const int SQ = 350; const int MOD = 998244353; typedef pair <int,int> pii; struct comp_node { int cur; long long cost,mnu,mnv; }; bool operator < (comp_node x,comp_node y) { if (x.cost == y.cost) { if (x.mnu == y.mnu) return x.mnv > y.mnv; return x.mnu > y.mnu; } return x.cost > y.cost; } struct node { int cur; long long cost; }; bool operator < (node x,node y) { return x.cost > y.cost; } priority_queue <node> Q; priority_queue <comp_node> CQ; vector <pair <int,int> > ed[N]; int n,m,s,t,u,v; long long sp,cu[N],cv[N],tu[N],tv[N],ans = LINF,vis[N]; void sp_s(){ for (int i = 1 ; i <= n ; i++) vis[i] = LINF; for (int i = 1 ; i <= n ; i++) tu[i] = tv[i] = LINF; CQ.push({s,0,cu[s],cv[s]}); while(len(CQ)) { auto temp = CQ.top(); CQ.pop(); int cur = temp.cur; long long cost = temp.cost,mnu = temp.mnu,mnv = temp.mnv; if (vis[cur] < cost) continue; if (vis[cur] == cost && tu[cur] <= mnu && tv[cur] <= mnv) continue; tu[cur] = min(tu[cur],mnu); tv[cur] = min(tv[cur],mnv); vis[cur] = cost; if (cur == t) ans = min(ans,mnu + mnv); for (auto i : ed[cur]) CQ.push({i.fi,cost + i.sc,min(mnu,cu[i.fi]),min(mnv,cv[i.fi])}); } while(len(CQ)) CQ.pop(); memset(vis,0,sizeof vis); } void sp_u(){ Q.push({u,0}); while(len(Q)) { auto temp = Q.top(); Q.pop(); int cur = temp.cur; long long cost = temp.cost; if (vis[cur]) continue; vis[cur] = 1; cu[cur] = cost; for (auto i : ed[cur]) Q.push({i.fi,cost + i.sc}); } memset(vis,0,sizeof vis); while(len(Q)) Q.pop(); } void sp_v(){ Q.push({v,0}); while(len(Q)) { auto temp = Q.top(); Q.pop(); int cur = temp.cur; long long cost = temp.cost; if (vis[cur]) continue; vis[cur] = 1; cv[cur] = cost; for (auto i : ed[cur]) Q.push({i.fi,cost + i.sc}); } memset(vis,0,sizeof vis); while(len(Q)) Q.pop(); } int main() { scanf("%d %d %d %d %d %d",&n,&m,&s,&t,&u,&v); for (int i = 1 ; i <= m ; i++) { int u,v,c; scanf("%d %d %d",&u,&v,&c); ed[u].pb(mp(v,c)); ed[v].pb(mp(u,c)); } sp_u(); sp_v(); sp_s(); printf("%lld\n",min(ans,cu[v])); }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:114:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d %d %d",&n,&m,&s,&t,&u,&v);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:117:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&u,&v,&c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...