Submission #1097783

#TimeUsernameProblemLanguageResultExecution timeMemory
1097783tvgkCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
195 ms27132 KiB
#include<bits/stdc++.h> using namespace std; #define task "NETWORK" #define se second #define fi first #define ll long long #define ii pair<ll, ll> const long mxN = 2e5 + 7; const ll inf = 1e18; int m, n, p[3]; vector<ii> w[mxN]; ll dp[10][mxN], mn[2][mxN]; void Dij(bool id) { for (int i = 1; i <= n; i++) mn[id][i] = inf; mn[id][p[id]] = 0; priority_queue<ii, vector<ii>, greater<ii>> pq; pq.push({0, p[id]}); while (pq.size()) { ii j = pq.top(); pq.pop(); if (j.fi != mn[id][j.se]) continue; for (ii i : w[j.se]) { if (j.fi + i.se < mn[id][i.fi]) { mn[id][i.fi] = j.fi + i.se; pq.push({j.fi + i.se, i.fi}); } } } } void Solve(int stt) { for (int i = 1; i <= n; i++) { for (int u = 1; u <= 4; u++) dp[u][i] = inf; } dp[4][stt] = 0; priority_queue<ii, vector<ii>, greater<ii>> pq; pq.push({0, stt}); while (pq.size()) { ii j = pq.top(); pq.pop(); if (j.fi != dp[4][j.se]) continue; for (int i = 0; i <= 1; i++) { for (int u = 0; u < 4; u++) dp[u | (1 << i)][j.se] = min(dp[u | (1 << i)][j.se], dp[u][j.se] + mn[i][j.se]); } for (ii i : w[j.se]) { if (j.fi + i.se < dp[4][i.fi]) { for (int u = 1; u < 4; u++) dp[u][i.fi] = inf; dp[4][i.fi] = j.fi + i.se; pq.push({j.fi + i.se, i.fi}); } if (j.fi + i.se == dp[4][i.fi]) { for (int u = 1; u < 4; u++) dp[u][i.fi] = min(dp[u][i.fi], dp[u][j.se]); } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; int stt, en; cin >> stt >> en; cin >> p[0] >> p[1]; for (int i = 1; i <= m; i++) { int u, v, dis; cin >> u >> v >> dis; w[u].push_back({v, dis}); w[v].push_back({u, dis}); } for (int i = 0; i <= 1; i++) Dij(i); Solve(stt); cout << min(mn[0][p[1]], dp[3][en]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...