Submission #99451

#TimeUsernameProblemLanguageResultExecution timeMemory
99451psmaoCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
103 ms3448 KiB
#include <bits/stdc++.h> using namespace std; #define fo(i,s,t) for(int i = s; i <= t; ++ i) #define fd(i,s,t) for(int i = s; i >= t; -- i) #define bf(i,s) for(int i = head[s]; i; i = e[i].next) #define mp make_pair #define fi first #define se second #define pii pair<int,int> #define pb push_back #define VI vector<int> #define sf scanf #define pf printf #define fp freopen #define SZ(x) ((int)(x).size()) #ifdef MPS #define D(x...) printf(x) #else #define D(x...) #endif typedef long long ll; typedef double db; typedef unsigned long long ull; const int inf = 1<<30; const ll INF = 1ll<<59; const db Inf = 1e20; const db eps = 1e-9; void gmax(int &a,int b){a = (a > b ? a : b);} void gmin(int &a,int b){a = (a < b ? a : b);} const int maxn = 100050; int n, m, s, t, u, v, head[maxn], tot, pre[maxn]; struct edge{int next, to, w;}e[maxn<<1]; ll dist[maxn]; bool inq[maxn]; priority_queue<pii,vector<pii>,greater<pii> > pq; void add_edge(int u, int v, int w) { e[tot] = (struct edge){head[u], v, w}; head[u] = tot++; e[tot] = (struct edge){head[v], u, w}; head[v] = tot++; } ll dijkstra(int s, int t) { pq.push(mp(0, s)); fo(i,1,n) dist[i] = INF; dist[s] = 0; while(!pq.empty()) { int h = pq.top().se; pq.pop(); inq[h] = false; for(int i = head[h]; i != -1; i = e[i].next) { int v = e[i].to; if(dist[v] > dist[h] + e[i].w) { dist[v] = dist[h] + e[i].w; pre[v] = i; if(!inq[v]) inq[v] = true, pq.push(mp(dist[v], v)); } } } return dist[t]; } void back_track(int t) { if(t == s) return; e[pre[t]].w = 0; back_track(e[pre[t]^1].to); } int main() { #ifdef MPS fp("1.in","r",stdin); fp("1.out","w",stdout); #endif sf("%d%d",&n,&m); sf("%d%d%d%d",&s,&t,&u,&v); memset(head, -1, sizeof(head)); fo(i,1,m) { int u, v, w; sf("%d%d%d",&u,&v,&w); add_edge(u, v, w); } return 0; dijkstra(s, t); back_track(t); pf("%lld\n",dijkstra(u, v)); return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:79:4: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  sf("%d%d",&n,&m);
    ^
commuter_pass.cpp:80:4: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  sf("%d%d%d%d",&s,&t,&u,&v);
    ^
commuter_pass.cpp:85:5: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   sf("%d%d%d",&u,&v,&w);
     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...