제출 #1087573

#제출 시각아이디문제언어결과실행 시간메모리
1087573MinhKienCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
232 ms44848 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; const int N = 5e5 + 10; #define ll long long #define li pair <ll, int> int n, m, a, b, c, d; int x, y; ll k; vector <li> v[N]; ll disA[N], disB[N], disC[N], disD[N]; void dijkstra(int s, ll dis[]) { fill_n(dis, N, 1e17); dis[s] = 0; priority_queue < li, vector <li>, greater <li> > q; q.push(li(0, s)); while (!q.empty()) { li p = q.top(); q.pop(); int u = p.second; ll w = p.first; if (dis[u] < w) continue; for (li z: v[u]) { if (z.first + w < dis[z.second]) { dis[z.second] = z.first + w; q.push(li(dis[z.second], z.second)); } } } } void pre() { dijkstra(a, disA); dijkstra(b, disB); dijkstra(c, disC); dijkstra(d, disD); } ll dp[2][N], best = 1e17; bool vis[N]; void dfs(int s) { vis[s] = true; dp[0][s] = dp[1][s] = 1e17; for (li i: v[s]) { int z = i.second; if (disA[z] + disB[z] != disA[b]) continue; if (!vis[z]) { dfs(z); } dp[0][s] = min(dp[0][s], dp[0][z]); dp[1][s] = min(dp[1][s], dp[1][z]); } best = min(best, disC[s] + dp[1][s]); best = min(best, dp[0][s] + disD[s]); dp[0][s] = min(dp[0][s], disC[s]); dp[1][s] = min(dp[1][s], disD[s]); } void solve() { best = disC[d]; dfs(a); cout << best << "\n"; } int main() { cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false); cin >> n >> m >> a >> b >> c >> d; for (int i = 1; i <= m; ++i) { cin >> x >> y >> k; v[x].push_back(li(k, y)); v[y].push_back(li(k, x)); } pre(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...