Submission #1102557

#TimeUsernameProblemLanguageResultExecution timeMemory
1102557vjudge1Travelling Merchant (CCO21_day2problem1)C++17
25 / 25
135 ms24512 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair <int, int> #define fi first #define se second #define mp make_pair const int NM = 2e5, inf = 1e18; int N, M, u[NM+5], v[NM+5], r[NM+5], p[NM+5], od[NM+5]; vector <int> g[NM+5]; int deg[NM+5]; stack <int> st; bool del[NM+5]; priority_queue <pair <pii, pii> > pq; int ans[NM+5]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> M; for (int i = 1; i <= M; i++){ cin >> u[i] >> v[i] >> r[i] >> p[i]; g[v[i]].push_back(i); deg[u[i]]++; od[i] = i; } sort(od+1, od+1+M, [&](int i, int j){ return r[i] > r[j]; }); for (int i = 1; i <= N; i++) if (!deg[i]) st.push(i); while (!st.empty()){ int x = st.top(); st.pop(); for (int i : g[x]){ del[i] = 1; deg[u[i]]--; if (!deg[u[i]]) st.push(u[i]); } } for (int i = 1; i <= N; i++) ans[i] = +inf; for (int t = 1; t <= M; t++){ int i = od[t]; if (del[i]) continue; del[i] = 1; ans[u[i]] = min(ans[u[i]], r[i]); deg[u[i]]--; if (deg[u[i]]) continue; st.push(u[i]); while (!st.empty()){ int x = st.top(); st.pop(); for (int i : g[x]){ if (del[i]) continue; del[i] = 1; ans[u[i]] = min(ans[u[i]], max(ans[v[i]]-p[i], r[i])); deg[u[i]]--; if (!deg[u[i]]) st.push(u[i]); } } } for (int i = 1; i <= N; i++) cout << (ans[i] == +inf ? -1 : ans[i]) << ' '; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...