Submission #1161696

#TimeUsernameProblemLanguageResultExecution timeMemory
1161696tw20000807Robot (JOI21_ho_t4)C++20
0 / 100
3095 ms58748 KiB
#include<bits/stdc++.h> #define int long long #define all(v) v.begin(), v.end() #define SZ(x) (int)x.size() #define pii pair<int, int> #define X first #define Y second using namespace std; const int maxn = 2e5 + 10; const int mod = 1e9 + 7;// 998244353; const int llmx = 1e18; void sol(){ int n, m; cin >> n >> m; vector< vector< array<int, 3> > > g(n + 1); vector< map<int, int> > cnt(n + 1); vector< map<pii, int> > dis(n + 1); while(m--){ int a, b, c, p; cin >> a >> b >> c >> p; cnt[a][c] += p; cnt[b][c] += p; g[a].push_back({b, c, p}); g[b].push_back({a, c, p}); } priority_queue< array<int, 4>, vector< array<int, 4> >, greater< array<int, 4> > > pq; dis[1][{0, 0}] = 0; pq.push({0, 1, 0, 0}); while(!pq.empty()){ auto [D, cur, cost, col] = pq.top(); pq.pop(); if(dis[cur][{cost, col}] != D) continue; for(auto &[nxt, c, p] : g[cur]){ if(!dis[nxt].count({p, c})) dis[nxt][{p, c}] = llmx; if(!dis[nxt].count({0, 0})) dis[nxt][{0, 0}] = llmx; if(dis[nxt][{p, c}] > D + p){ dis[nxt][{p, c}] = D + p; pq.push({dis[nxt][{p, c}], nxt, p, c}); } if(dis[nxt][{0, 0}] > D + max(0LL, cnt[cur][c] - p - (c == col ? cost : 0))){ dis[nxt][{0, 0}] = D + cnt[cur][c] - p; pq.push({dis[nxt][{0, 0}], nxt, 0, 0}); } } } int ans = llmx; for(auto &[_, g] : dis[n]) ans = min(ans, g); cout << ans << "\n"; } /* 4 6 1 4 4 4 3 4 1 3 1 3 4 4 2 4 3 1 2 3 3 2 1 2 4 2 // 3 */ signed main(){ ios::sync_with_stdio(0), cin.tie(0), cerr.tie(0); int t = 1; //cin >> t; while(t--) sol(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...