제출 #1158044

#제출 시각아이디문제언어결과실행 시간메모리
1158044vladiliusRobot (JOI21_ho_t4)C++20
0 / 100
3095 ms54784 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second #define arr3 array<int, 3> #define arr4 array<ll, 4> int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin>>n>>m; vector<arr3> g[n + 1]; vector<map<int, int>> mp(n + 1); while (m--){ int x, y, c, w; cin>>x>>y>>c>>w; g[x].pb({y, c, w}); g[y].pb({x, c, w}); mp[x][c]++; mp[y][c]++; } queue<arr4> q; q.push({1, 0, 0, 0}); vector<map<int, ll>> dist(n + 1); dist[1][0] = 0; while (!q.empty()){ auto [v, k, P, ds] = q.front(); q.pop(); for (auto [u, c, w]: g[v]){ int cc = mp[v][c] - (c == k); ll f = ds + w; if (dist[u].find(c) == dist[u].end()){ dist[u][c] = f; q.push({u, c, v, f}); } else if (f < dist[u][c]){ dist[u][c] = f; q.push({u, c, v, f}); } if (u == P && k){ assert(c == k); if (dist[u].find(k) == dist[u].end()){ dist[u][k] = ds; q.push({u, k, v, ds}); } else if (ds < dist[u][k]){ dist[u][k] = ds; q.push({u, k, v, ds}); } } if (cc <= 1){ ll f = ds; if (dist[u].find(0) == dist[u].end()){ dist[u][0] = f; q.push({u, 0, v, f}); } else if (f < dist[u][0]){ dist[u][0] = f; q.push({u, 0, v, f}); } } } } if (dist[n].empty()){ cout<<-1<<"\n"; } else { ll out = 1e18; for (auto [x, y]: dist[n]) out = min(out, y); cout<<out<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...