Submission #52304

#TimeUsernameProblemLanguageResultExecution timeMemory
52304evpipisCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
1512 ms70656 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair typedef long long ll; typedef pair<int, int> ii; const int len = 1e5+5; const ll inf = 1e16; int n, m, s1, t1, s2, t2, best[len]; ll dis[5][len]; vector<ii> adj[len]; priority_queue<pair<ll, ii>, vector<pair<ll, ii> >, greater<pair<ll, ii> > > pq; void dfs(int u){ //printf("best %d\n", u); best[u] = 1; for (int j = 0; j < adj[u].size(); j++){ ii v = adj[u][j]; if (!best[v.fi] && dis[4][v.fi]+v.se == dis[4][u]) dfs(v.fi); } } void path(int s, int hey){ if (!hey){ for (int j = 1; j <= n; j++) dis[4][j] = inf; } else{ for (int i = 0; i < 4; i++) for (int j = 1; j <= n; j++) dis[i][j] = inf; } if (!hey){ pq.push(mp(0, mp(4, s))); } else{ pq.push(mp(0, mp(0, s))); if (best[s]) pq.push(mp(0, mp(1, s))), pq.push(mp(0, mp(2, s))); } while (!pq.empty()){ pair<ll, ii> top = pq.top(); pq.pop(); int t = top.se.fi, u = top.se.se; ll d = top.fi; if (dis[t][u] != inf) continue; dis[t][u] = d; //printf("(%d, %d) -> %lld\n", t, u, d); for (int j = 0; j < adj[u].size(); j++){ ii v = adj[u][j]; if (t == 0){ pq.push(mp(d+v.se, mp(0, v.fi))); if (best[v.fi]) pq.push(mp(d+v.se, mp(1, v.fi))), pq.push(mp(d+v.se, mp(2, v.fi))); } else if (t == 1){ pq.push(mp(d+v.se, mp(3, v.fi))); if (best[v.fi] && dis[4][u]-dis[4][v.fi] == (ll)v.se) pq.push(mp(d, mp(1, v.fi))); } else if (t == 2){ pq.push(mp(d+v.se, mp(3, v.fi))); if (best[v.fi] && dis[4][u]-dis[4][v.fi] == -(ll)v.se) pq.push(mp(d, mp(2, v.fi))); } else if (t == 3){ pq.push(mp(d+v.se, mp(3, v.fi))); } else{ pq.push(mp(d+v.se, mp(4, v.fi))); } } } } int main(){ scanf("%d %d %d %d %d %d", &n, &m, &s1, &t1, &s2, &t2); for (int i = 0; i < m; i++){ int a, b, c; scanf("%d %d %d", &a, &b, &c); adj[a].pb(mp(b, c)); adj[b].pb(mp(a, c)); } path(s1, 0); dfs(t1); path(s2, 1); ll ans = min(min(dis[0][t2], dis[1][t2]), min(dis[2][t2], dis[3][t2])); printf("%lld\n", ans); return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'void dfs(int)':
commuter_pass.cpp:21:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < adj[u].size(); j++){
                     ~~^~~~~~~~~~~~~~~
commuter_pass.cpp: In function 'void path(int, int)':
commuter_pass.cpp:61:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < adj[u].size(); j++){
                         ~~^~~~~~~~~~~~~~~
commuter_pass.cpp: In function 'int main()':
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, &s1, &t1, &s2, &t2);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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", &a, &b, &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...