Submission #1277336

#TimeUsernameProblemLanguageResultExecution timeMemory
1277336nanaseyuzukiRobot (JOI21_ho_t4)C++20
0 / 100
105 ms17472 KiB
#include <bits/stdc++.h> // Author: Kazuki_Will_Win_VOI_8703 #define fi first #define se second #define pii pair<int, int> #define int long long #define all(a) a.begin(), a.end() using namespace std; const int mn = 1e5 + 5, inf = 1e18; int n, m, d[mn], cnt[mn]; vector <tuple<int, int, int>> a[mn]; void solve(){ cin >> n >> m; for(int i = 1; i <= m; i++){ int u, v, c, p; cin >> u >> v >> c >> p; a[u].push_back({v, c, p}); a[v].push_back({u, c, p}); } fill(d, d + mn, inf); priority_queue<pii, vector<pii>, greater<pii>> pq; d[1] = 0; pq.push({d[1], 1}); while(pq.size()){ auto [c, u] = pq.top(); pq.pop(); if(c > d[u]) continue; for(auto [v, c, p] : a[u]) cnt[c] ++; for(auto [v, c, p] : a[u]){ if(cnt[c] >= 2){ if(d[v] > d[u] + p){ d[v] = d[u] + p; pq.push({d[v], v}); } } else{ if(d[v] > d[u]){ d[v] = d[u]; pq.push({d[v], v}); } } } for(auto [v, c, p] : a[u]) cnt[c] = 0; } if(d[n] == inf) d[n] = -1; cout << d[n] << '\n'; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...