Submission #673478

# Submission time Handle Problem Language Result Execution time Memory
673478 2022-12-20T16:43:46 Z Lobo Pipes (BOI13_pipes) C++17
74.0741 / 100
239 ms 45700 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;
    for(int i = 1; i <= n; i++) {
        cin >> c[i];
    }
    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]++;
    }

    if(m != n-1) {
        cout << 0 << endl;
        return;
    }
    if(n == 2) {
        cout << 2*c[1] << endl;
        return;
    }
    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 6 ms 12116 KB Output is correct
4 Correct 60 ms 20348 KB Output is correct
5 Correct 7 ms 11988 KB Output is correct
6 Correct 7 ms 11988 KB Output is correct
7 Correct 8 ms 12032 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 9 ms 12116 KB Output is correct
10 Correct 7 ms 12188 KB Output is correct
11 Correct 7 ms 12244 KB Output is correct
12 Correct 7 ms 12112 KB Output is correct
13 Correct 49 ms 18688 KB Output is correct
14 Correct 55 ms 19836 KB Output is correct
15 Correct 63 ms 20376 KB Output is correct
16 Correct 53 ms 19080 KB Output is correct
17 Correct 75 ms 20288 KB Output is correct
18 Correct 70 ms 20364 KB Output is correct
19 Correct 60 ms 20044 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 20332 KB Output is correct
23 Correct 47 ms 18636 KB Output is correct
24 Correct 67 ms 20344 KB Output is correct
25 Correct 51 ms 18892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 12080 KB Output isn't correct
2 Incorrect 7 ms 12116 KB Output isn't correct
3 Correct 45 ms 19768 KB Output is correct
4 Correct 48 ms 20300 KB Output is correct
5 Correct 47 ms 20092 KB Output is correct
6 Correct 187 ms 45700 KB Output is correct
7 Incorrect 7 ms 11988 KB Output isn't correct
8 Incorrect 6 ms 11988 KB Output isn't correct
9 Correct 8 ms 11988 KB Output is correct
10 Correct 6 ms 11988 KB Output is correct
11 Correct 6 ms 12064 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 11988 KB Output is correct
14 Incorrect 8 ms 11988 KB Output isn't correct
15 Incorrect 7 ms 12116 KB Output isn't correct
16 Incorrect 7 ms 12116 KB Output isn't correct
17 Correct 6 ms 12116 KB Output is correct
18 Correct 7 ms 12116 KB Output is correct
19 Correct 9 ms 12116 KB Output is correct
20 Correct 6 ms 12116 KB Output is correct
21 Correct 6 ms 12244 KB Output is correct
22 Incorrect 6 ms 12100 KB Output isn't correct
23 Incorrect 53 ms 18900 KB Output isn't correct
24 Incorrect 57 ms 20300 KB Output isn't correct
25 Correct 46 ms 19832 KB Output is correct
26 Correct 48 ms 20304 KB Output is correct
27 Correct 46 ms 20160 KB Output is correct
28 Correct 47 ms 20660 KB Output is correct
29 Correct 155 ms 39256 KB Output is correct
30 Incorrect 46 ms 20080 KB Output isn't correct
31 Incorrect 63 ms 20228 KB Output isn't correct
32 Incorrect 48 ms 20372 KB Output isn't correct
33 Correct 51 ms 20252 KB Output is correct
34 Correct 57 ms 20284 KB Output is correct
35 Correct 51 ms 20304 KB Output is correct
36 Correct 46 ms 20300 KB Output is correct
37 Correct 239 ms 45692 KB Output is correct
38 Incorrect 47 ms 20300 KB Output isn't correct
39 Incorrect 43 ms 20148 KB Output isn't correct
40 Incorrect 49 ms 20248 KB Output isn't correct
41 Correct 50 ms 20300 KB Output is correct
42 Correct 68 ms 20236 KB Output is correct
43 Correct 52 ms 20268 KB Output is correct
44 Correct 45 ms 19964 KB Output is correct
45 Correct 134 ms 41784 KB Output is correct
46 Incorrect 50 ms 20280 KB Output isn't correct
47 Incorrect 44 ms 20300 KB Output isn't correct
48 Incorrect 48 ms 20340 KB Output isn't correct
49 Correct 48 ms 19772 KB Output is correct
50 Correct 48 ms 20248 KB Output is correct
51 Correct 46 ms 20308 KB Output is correct
52 Correct 43 ms 20132 KB Output is correct
53 Correct 150 ms 41408 KB Output is correct
54 Incorrect 45 ms 20172 KB Output isn't correct