Submission #1109649

# Submission time Handle Problem Language Result Execution time Memory
1109649 2024-11-07T08:51:15 Z thangdz2k7 Travelling Merchant (CCO21_day2problem1) C++17
25 / 25
143 ms 25940 KB
// 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), used(m, 0);
    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]){
            used[id] = 1;
            if (!--deg[e[id].u]) qu.push(e[id].u);
        }
    }

    priority_queue <pair <int, int>> pq;
    for (int id = 0; id < m; ++ id){
        if (!used[id]) pq.push({e[id].r, id});
    }
    while (pq.size()){
        auto [ru, id] = pq.top(); pq.pop();
        if (used[id]) continue;
        used[id] = 1;
        int u = e[id].u;
        if (!--deg[u]){
            ans[u] = ru;
            for (int id : radj[u]) if (!used[id] && e[id].r < ru - e[id].p) {
                int v = e[id].u;
                pq.push({ru - e[id].p, id});
            }
        }
    }

    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

Main.cpp:18:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
Main.cpp:18:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
Main.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
Main.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
Main.cpp: In function 'void solve()':
Main.cpp:63:21: warning: unused variable 'v' [-Wunused-variable]
   63 |                 int v = e[id].u;
      |                     ^
Main.cpp: In function 'int main()':
Main.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen("pqh.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen("pqh.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 15432 KB Output is correct
2 Correct 81 ms 15432 KB Output is correct
3 Correct 71 ms 12480 KB Output is correct
4 Correct 19 ms 8528 KB Output is correct
5 Correct 109 ms 18360 KB Output is correct
6 Correct 106 ms 18376 KB Output is correct
7 Correct 71 ms 12384 KB Output is correct
8 Correct 133 ms 25828 KB Output is correct
9 Correct 127 ms 23688 KB Output is correct
10 Correct 79 ms 11832 KB Output is correct
11 Correct 107 ms 17120 KB Output is correct
12 Correct 54 ms 10436 KB Output is correct
13 Correct 51 ms 9956 KB Output is correct
14 Correct 139 ms 25728 KB Output is correct
15 Correct 126 ms 25784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 80 ms 15432 KB Output is correct
16 Correct 81 ms 15432 KB Output is correct
17 Correct 71 ms 12480 KB Output is correct
18 Correct 19 ms 8528 KB Output is correct
19 Correct 109 ms 18360 KB Output is correct
20 Correct 106 ms 18376 KB Output is correct
21 Correct 71 ms 12384 KB Output is correct
22 Correct 133 ms 25828 KB Output is correct
23 Correct 127 ms 23688 KB Output is correct
24 Correct 79 ms 11832 KB Output is correct
25 Correct 107 ms 17120 KB Output is correct
26 Correct 54 ms 10436 KB Output is correct
27 Correct 51 ms 9956 KB Output is correct
28 Correct 139 ms 25728 KB Output is correct
29 Correct 126 ms 25784 KB Output is correct
30 Correct 85 ms 20180 KB Output is correct
31 Correct 81 ms 20304 KB Output is correct
32 Correct 63 ms 11452 KB Output is correct
33 Correct 21 ms 8528 KB Output is correct
34 Correct 107 ms 18364 KB Output is correct
35 Correct 123 ms 18544 KB Output is correct
36 Correct 67 ms 12480 KB Output is correct
37 Correct 128 ms 25940 KB Output is correct
38 Correct 136 ms 24576 KB Output is correct
39 Correct 63 ms 11704 KB Output is correct
40 Correct 113 ms 17084 KB Output is correct
41 Correct 56 ms 10428 KB Output is correct
42 Correct 51 ms 9788 KB Output is correct
43 Correct 135 ms 25784 KB Output is correct
44 Correct 143 ms 25792 KB Output is correct
45 Correct 132 ms 25784 KB Output is correct
46 Correct 90 ms 17652 KB Output is correct
47 Correct 96 ms 16708 KB Output is correct
48 Correct 112 ms 17372 KB Output is correct
49 Correct 105 ms 17084 KB Output is correct
50 Correct 1 ms 336 KB Output is correct