| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1109638 | thangdz2k7 | Travelling Merchant (CCO21_day2problem1) | C++17 | 80 ms | 19536 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// author : thembululquaUwU
// 3.9.2024
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}
struct Edge{
    int u, v, r, p;
};
void solve(){
    int n, m;
    cin >> n >> m;
    vector <Edge> e(m); m = 0;
    vector <vector <int>> radj(n);
    vector <int> deg(n);
    for (auto &[u, v, r, p] : e) {
        cin >> u >> v >> r >> p;
        -- u, -- v;
        radj[v].push_back(m ++);
        deg[u] ++;
    }
    vector <int> ans(n, -1);
    queue <int> qu;
    for (int u = 0; u < n; ++ u){
        if (!deg[u]) qu.push(u);
    }
    while (qu.size()){
        int u = qu.front(); qu.pop();
        for (int id : radj[u]){
            if (!--deg[e[id].u]) qu.push(e[id].u);
        }
    }
    priority_queue <pair <int, int>> pq;
    for (int id = 0; id < m; ++ id){
        if (deg[e[id].u]) pq.push({e[id].r, id});
    }
    while (pq.size()){
        auto [ru, id] = pq.top(); pq.pop();
        int u = e[id].u;
        if (ans[u] > -1) continue;
        if (!--deg[u]){
            ans[u] = ru;
            for (int ri : radj[u]) if (e[ri].r < ru - e[ri].p) {
                pq.push({ru - e[ri].p, ri});
            }
        }
    }
    for (int i = 0; i < n; ++ i) cout << ans[i] << ' ';
}
int main(){
    if (fopen("pqh.inp", "r")){
        freopen("pqh.inp", "r", stdin);
        freopen("pqh.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
