Submission #673474

# Submission time Handle Problem Language Result Execution time Memory
673474 2022-12-20T16:40:20 Z Lobo Pipes (BOI13_pipes) C++17
74.0741 / 100
69 ms 20520 KB
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 5e5+10;

int n, m, c[maxn], ans[maxn], gr[maxn];
vector<pair<int,int>> g[maxn];

void solve() {
    cin >> n >> m;
    if(m != n-1) {
        cout << 0 << endl;
        return;
    }
    for(int i = 1; i <= n; i++) {
        cin >> c[i];
    }
    if(n == 2) {
        cout << 2*c[1] << endl;
        return;
    }
    for(int i = 1; i <= m; i++) {
        int u,v; cin >> u >> v;
        g[u].pb(mp(v,i));
        g[v].pb(mp(u,i));
        gr[u]++;
        gr[v]++;
    }
    queue<int> q;
    for(int i = 1; i <= n; i++) {
        if(gr[i] == 1) q.push(i);
    }


    while(q.size()) {
        int u = q.front(); q.pop();
        gr[u] = -1;
        for(auto V : g[u]) {
            int v = V.fr;
            int id = V.sc;
            if(gr[v] == -1) continue;
            ans[id] = 2*c[u];
            c[v]-= c[u];
            if(--gr[v] == 1) q.push(v);
        }
    }

    for(int i = 1; i <= m; i++) {
        cout << ans[i] << endl;
    }
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }

}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 7 ms 12080 KB Output is correct
4 Correct 60 ms 20432 KB Output is correct
5 Correct 7 ms 12060 KB Output is correct
6 Correct 7 ms 12012 KB Output is correct
7 Correct 8 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 9 ms 12116 KB Output is correct
10 Correct 6 ms 12116 KB Output is correct
11 Correct 7 ms 12116 KB Output is correct
12 Correct 6 ms 12128 KB Output is correct
13 Correct 57 ms 18728 KB Output is correct
14 Correct 59 ms 20036 KB Output is correct
15 Correct 61 ms 20520 KB Output is correct
16 Correct 56 ms 19156 KB Output is correct
17 Correct 69 ms 20436 KB Output is correct
18 Correct 64 ms 20500 KB Output is correct
19 Correct 69 ms 20104 KB Output is correct
20 Correct 6 ms 11988 KB Output is correct
21 Correct 7 ms 12116 KB Output is correct
22 Correct 60 ms 20508 KB Output is correct
23 Correct 51 ms 18736 KB Output is correct
24 Correct 62 ms 20464 KB Output is correct
25 Correct 54 ms 19148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 11988 KB Output isn't correct
2 Incorrect 6 ms 11988 KB Output isn't correct
3 Correct 8 ms 12116 KB Output is correct
4 Correct 7 ms 12116 KB Output is correct
5 Correct 6 ms 12060 KB Output is correct
6 Correct 7 ms 12100 KB Output is correct
7 Incorrect 7 ms 12076 KB Output isn't correct
8 Incorrect 7 ms 11988 KB Output isn't correct
9 Correct 6 ms 11988 KB Output is correct
10 Correct 6 ms 11988 KB Output is correct
11 Correct 6 ms 11988 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 11988 KB Output is correct
14 Incorrect 6 ms 11988 KB Output isn't correct
15 Incorrect 7 ms 12080 KB Output isn't correct
16 Incorrect 6 ms 11988 KB Output isn't correct
17 Correct 7 ms 12116 KB Output is correct
18 Correct 7 ms 12024 KB Output is correct
19 Correct 7 ms 12032 KB Output is correct
20 Correct 7 ms 11988 KB Output is correct
21 Correct 6 ms 12020 KB Output is correct
22 Incorrect 6 ms 11992 KB Output isn't correct
23 Incorrect 6 ms 12116 KB Output isn't correct
24 Incorrect 8 ms 12096 KB Output isn't correct
25 Correct 7 ms 12116 KB Output is correct
26 Correct 6 ms 12116 KB Output is correct
27 Correct 6 ms 12116 KB Output is correct
28 Correct 6 ms 12116 KB Output is correct
29 Correct 6 ms 12116 KB Output is correct
30 Incorrect 7 ms 12084 KB Output isn't correct
31 Incorrect 6 ms 12000 KB Output isn't correct
32 Incorrect 6 ms 12116 KB Output isn't correct
33 Correct 7 ms 12092 KB Output is correct
34 Correct 7 ms 12116 KB Output is correct
35 Correct 10 ms 12116 KB Output is correct
36 Correct 7 ms 12128 KB Output is correct
37 Correct 8 ms 12116 KB Output is correct
38 Incorrect 8 ms 12116 KB Output isn't correct
39 Incorrect 8 ms 12116 KB Output isn't correct
40 Incorrect 8 ms 12084 KB Output isn't correct
41 Correct 6 ms 12116 KB Output is correct
42 Correct 6 ms 12116 KB Output is correct
43 Correct 7 ms 12092 KB Output is correct
44 Correct 6 ms 12116 KB Output is correct
45 Correct 6 ms 12088 KB Output is correct
46 Incorrect 6 ms 12116 KB Output isn't correct
47 Incorrect 7 ms 12068 KB Output isn't correct
48 Incorrect 6 ms 12088 KB Output isn't correct
49 Correct 6 ms 12116 KB Output is correct
50 Correct 6 ms 12116 KB Output is correct
51 Correct 6 ms 12088 KB Output is correct
52 Correct 6 ms 12116 KB Output is correct
53 Correct 7 ms 12088 KB Output is correct
54 Incorrect 6 ms 12016 KB Output isn't correct