Submission #755490

# Submission time Handle Problem Language Result Execution time Memory
755490 2023-06-10T07:40:56 Z The_Samurai Pipes (BOI13_pipes) C++17
74.0741 / 100
68 ms 8240 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int n, m;
    cin >> n >> m;
    if (n != m + 1) {
        cout << 0;
        return 0;
    }
    vector<vector<pair<int, int>>> g(n + 1);
    vector<int> cnt(n + 1), ans(m), a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(v, i);
        g[v].emplace_back(u, i);
    }
    queue<int> q;
    vector<bool> vis(n + 1);
    for (int i = 1; i <= n; i++) {
        cnt[i] = g[i].size();
        if (cnt[i] == 1) {
            q.push(i);
        }
    }
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        vis[u] = true;
        for (auto [v, i]: g[u]) {
            if (vis[v]) continue;
            cnt[v]--;
            if (cnt[v] == 1) q.push(v);
            ans[i] = a[u] * 2;
            a[v] -= a[u];
        }
    }
    for (int x: ans) cout << x << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 65 ms 8160 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 46 ms 6516 KB Output is correct
14 Correct 61 ms 7752 KB Output is correct
15 Correct 68 ms 8196 KB Output is correct
16 Correct 47 ms 7016 KB Output is correct
17 Correct 57 ms 8180 KB Output is correct
18 Correct 59 ms 8196 KB Output is correct
19 Correct 53 ms 7392 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 58 ms 8240 KB Output is correct
23 Correct 39 ms 6604 KB Output is correct
24 Correct 59 ms 8204 KB Output is correct
25 Correct 50 ms 6852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Incorrect 1 ms 212 KB Output isn't correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Incorrect 1 ms 212 KB Output isn't correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Incorrect 1 ms 212 KB Output isn't correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Incorrect 0 ms 212 KB Output isn't correct
23 Incorrect 3 ms 212 KB Output isn't correct
24 Incorrect 1 ms 212 KB Output isn't correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Incorrect 1 ms 212 KB Output isn't correct
31 Incorrect 1 ms 212 KB Output isn't correct
32 Incorrect 1 ms 212 KB Output isn't correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Incorrect 0 ms 212 KB Output isn't correct
39 Incorrect 0 ms 212 KB Output isn't correct
40 Incorrect 1 ms 212 KB Output isn't correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Incorrect 1 ms 212 KB Output isn't correct
47 Incorrect 0 ms 212 KB Output isn't correct
48 Incorrect 0 ms 212 KB Output isn't correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Incorrect 1 ms 212 KB Output isn't correct