Submission #956489

#TimeUsernameProblemLanguageResultExecution timeMemory
956489pragmatistCommuter Pass (JOI18_commuter_pass)C++17
24 / 100
127 ms23172 KiB
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5+20; const int inf = (int)1e9+7; const long long INF = (long long)1e18+7; const int MOD = 42043; int sum(int x, int y) { x += y; if(x >= MOD) { x -= MOD; } return x; } int mult(int x, int y) { return 1ll*x*y%MOD; } int n, m, s1, t1, s2, t2; vector<pair<int, int> > g[N]; long long d[305][305]; void dijkstra(int tp, int s) { fill(d[tp], d[tp]+1+n, INF); d[tp][s] = 0; priority_queue<pair<long long, int> > q; q.push({0, s}); while(!q.empty()) { long long cur_d = -q.top().first; int v = q.top().second; q.pop(); for(auto [to, w] : g[v]) { if(d[tp][v]+w < d[tp][to]) { d[tp][to] = d[tp][v]+w; q.push({-d[tp][to], to}); } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> s1 >> t1 >> s2 >> t2; for(int i = 1; i <= m; ++i) { int u, v, w; cin >> u >> v >> w; g[u].push_back({v, w}); g[v].push_back({u, w}); } for(int i = 1; i <= n; ++i) { dijkstra(i, i); } long long ans = d[s2][t2]; for(int i = 1; i <= n; ++i) { for(int j = 1; j <= n; ++j) { if(d[s1][i]+d[i][j]+d[j][t1]==d[s1][t1]) { ans = min(ans, d[s2][i]+d[j][t2]); ans = min(ans, d[s2][j]+d[i][t2]); } } } cout << ans << "\n"; return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'void dijkstra(int, int)':
commuter_pass.cpp:32:13: warning: unused variable 'cur_d' [-Wunused-variable]
   32 |   long long cur_d = -q.top().first;
      |             ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...