Submission #1270203

#TimeUsernameProblemLanguageResultExecution timeMemory
1270203Born_To_LaughRobot (JOI21_ho_t4)C++17
100 / 100
132 ms15088 KiB
// Born_To_Laugh - Hughie Do #include <bits/stdc++.h> #define alle(AC) AC.begin(), AC.end() #define fi first #define se second using namespace std; typedef long long ll; [[maybe_unused]] const ll MOD = 998244353, INF = 2e18 + 7; /* there are two case to deal with: - fix the edge of a to elm - fix all other edge that have the same col as a-elm edge: + move to a with random edge + move to a with the same col edge */ const int maxn = 1e5 + 5; const int maxm = 2e5 + 5; int n, m; vector<array<int, 3>> adj[maxn]; priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<>> pq; vector<ll> dist(maxn, INF); ll sum[maxm];//sum[i] = sum all p of edge that have col i adjacent to a ll minn[maxm];//minn[i] = min d[elm] that have c(elm, a) = i void solve(){ cin >> n >> m; for(int i=1; i<=m; ++i){ int a, b, c, p;cin >> a >> b >> c >> p; adj[a].push_back({b, c, p}); adj[b].push_back({a, c, p}); } pq.push({0, 1}); dist[1] = 0; while(!pq.empty()){ int a = pq.top().se; ll d = pq.top().fi; pq.pop(); if(d > dist[a])continue; for(auto &[elm, col, p]: adj[a]){ sum[col] = 0; minn[col] = INF; } for(auto &[elm, col, p]: adj[a]){ sum[col] += p; minn[col] = min(minn[col], dist[elm]); } for(auto &[elm, col, p]: adj[a]){ ll nxt = min({ dist[a] + p, dist[a] + sum[col] - p, minn[col] + sum[col] - p }); if(dist[elm] > nxt){ dist[elm] = nxt; pq.push({dist[elm], elm}); } } } if(dist[n] == INF)cout << -1 << '\n'; else cout << dist[n] << '\n'; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...