제출 #82488

#제출 시각아이디문제언어결과실행 시간메모리
82488hatuank97lhpCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
5 ms2808 KiB
#include <bits/stdc++.h> #define LL long long #define F first #define S second #define mp make_pair using namespace std; void load() { #ifndef ONLINE_JUDGE freopen(".inp","r",stdin); freopen(".out","w",stdout); #endif // ONLINE_JUDGE } int n,m,a,b,c,d; const int N = 1e5 + 123; typedef pair < LL , int > II; vector < II > ed[N]; typedef pair < LL , II > IIII; LL dp[3][N],f[N][2],ans ; void dij(int s, int cs) { for (int i = 1 ; i <= n ; ++ i) dp[cs][i] = 1e18; dp[cs][s] = 0; priority_queue < II , vector < II > , greater < II > > q; q.push(mp(0,s)); while (!q.empty()) { II b = q.top(); q.pop(); if (b.F > dp[cs][b.S]) continue; for (II tmp : ed[b.S]) { int v = tmp.F, w = tmp.S; if (dp[cs][v] > b.F + w) dp[cs][v] = b.F + w, q.push(mp(dp[cs][v],v)); } } } void dij_2(int s) { for (int i = 1 ; i <= n ; ++ i) f[i][0] = f[i][1] = 1e18; f[s][0] = 0; if (dp[1][s] + dp[2][s] == dp[2][a]) f[s][1] = 0; priority_queue < IIII , vector <IIII>, greater < IIII > > q; q.push(mp(f[s][0],mp(s,0))); q.push(mp(f[s][1],mp(s,1))); while (!q.empty()) { IIII b = q.top(); q.pop(); if (f[b.S.F][b.S.S] < b.F) continue; for (II tmp : ed[b.S.F]) { int v = tmp.F, w = tmp.S, typ = b.S.S; if (typ == 0) { if (f[v][0] > b.F + w) f[v][0] = b.F + w, q.push(mp(f[v][0], mp(v,0))); if (dp[1][v] + dp[2][v] == dp[2][a] && f[v][1] > b.F + w) f[v][1] = b.F + w, q.push(mp(f[v][1], mp(v,1))); } if (typ == 1) { if (f[v][0] > b.F + w) f[v][0] = b.F + w, q.push(mp(f[v][0], mp(v,0))); int u = b.S.F;// cout << u << " " << v << " " << dp[1][u] << " " << dp[2][v] << endl; if (dp[1][u] + dp[2][v] + w == dp[2][a] && f[v][1] > b.F) f[v][1] = b.F, q.push(mp(f[v][1],mp(v,1))); } } } ans = min(ans,min(f[d][0],f[d][1])); return ; } void trungtt() { scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&d); for (int i = 1 ; i <= m ; ++ i) { int u,v,val; scanf("%d%d%d",&u,&v,&val); ed[u].push_back(mp(v,val)); ed[v].push_back(mp(u,val)); } ans = 1e18; dij(a,1); dij(b,2); dij_2(c); swap(a,b); dij(a,1); dij(b,2); dij_2(c); printf("%lld",ans); } int main() { load(); trungtt(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

commuter_pass.cpp: In function 'void load()':
commuter_pass.cpp:11:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(".inp","r",stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~
commuter_pass.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(".out","w",stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~
commuter_pass.cpp: In function 'void trungtt()':
commuter_pass.cpp:89:10: 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,&a,&b,&c,&d);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&u,&v,&val);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...