Submission #673473

# Submission time Handle Problem Language Result Execution time Memory
673473 2022-12-20T16:39:05 Z Lobo Pipes (BOI13_pipes) C++17
44.0741 / 100
64 ms 22028 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 Incorrect 6 ms 11988 KB Output isn't correct
2 Incorrect 6 ms 12080 KB Output isn't correct
3 Incorrect 6 ms 12116 KB Output isn't correct
4 Incorrect 58 ms 21964 KB Output isn't correct
5 Incorrect 6 ms 11988 KB Output isn't correct
6 Incorrect 7 ms 11988 KB Output isn't correct
7 Incorrect 6 ms 12080 KB Output isn't correct
8 Incorrect 6 ms 11988 KB Output isn't correct
9 Incorrect 7 ms 12116 KB Output isn't correct
10 Incorrect 6 ms 12084 KB Output isn't correct
11 Incorrect 7 ms 12152 KB Output isn't correct
12 Incorrect 7 ms 12136 KB Output isn't correct
13 Incorrect 47 ms 19968 KB Output isn't correct
14 Incorrect 57 ms 21440 KB Output isn't correct
15 Incorrect 61 ms 21972 KB Output isn't correct
16 Incorrect 50 ms 20424 KB Output isn't correct
17 Incorrect 60 ms 21988 KB Output isn't correct
18 Incorrect 59 ms 22000 KB Output isn't correct
19 Incorrect 64 ms 21836 KB Output isn't correct
20 Incorrect 6 ms 11988 KB Output isn't correct
21 Incorrect 6 ms 12080 KB Output isn't correct
22 Incorrect 61 ms 21948 KB Output isn't correct
23 Incorrect 50 ms 19920 KB Output isn't correct
24 Incorrect 62 ms 22028 KB Output isn't correct
25 Incorrect 49 ms 20252 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 11988 KB Output isn't correct
2 Incorrect 6 ms 12080 KB Output isn't correct
3 Correct 6 ms 12116 KB Output is correct
4 Correct 6 ms 12116 KB Output is correct
5 Correct 6 ms 12116 KB Output is correct
6 Correct 6 ms 12084 KB Output is correct
7 Incorrect 6 ms 11988 KB Output isn't correct
8 Incorrect 6 ms 11988 KB Output isn't correct
9 Correct 6 ms 12072 KB Output is correct
10 Correct 7 ms 12004 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 12076 KB Output is correct
14 Incorrect 6 ms 11988 KB Output isn't correct
15 Incorrect 6 ms 12088 KB Output isn't correct
16 Incorrect 6 ms 12000 KB Output isn't correct
17 Correct 6 ms 12080 KB Output is correct
18 Correct 6 ms 12000 KB Output is correct
19 Correct 6 ms 12080 KB Output is correct
20 Correct 8 ms 11988 KB Output is correct
21 Correct 6 ms 11988 KB Output is correct
22 Incorrect 6 ms 11988 KB Output isn't correct
23 Incorrect 6 ms 12116 KB Output isn't correct
24 Incorrect 6 ms 12116 KB Output isn't correct
25 Correct 6 ms 12088 KB Output is correct
26 Correct 6 ms 12104 KB Output is correct
27 Correct 6 ms 12116 KB Output is correct
28 Correct 7 ms 12116 KB Output is correct
29 Correct 6 ms 12116 KB Output is correct
30 Incorrect 6 ms 12116 KB Output isn't correct
31 Incorrect 6 ms 12116 KB Output isn't correct
32 Incorrect 6 ms 12116 KB Output isn't correct
33 Correct 6 ms 12092 KB Output is correct
34 Correct 6 ms 12116 KB Output is correct
35 Correct 6 ms 12084 KB Output is correct
36 Correct 6 ms 12116 KB Output is correct
37 Correct 6 ms 12116 KB Output is correct
38 Incorrect 6 ms 12092 KB Output isn't correct
39 Incorrect 8 ms 12072 KB Output isn't correct
40 Incorrect 6 ms 12116 KB Output isn't correct
41 Correct 7 ms 12092 KB Output is correct
42 Correct 6 ms 12092 KB Output is correct
43 Correct 8 ms 12116 KB Output is correct
44 Correct 6 ms 12084 KB Output is correct
45 Correct 6 ms 12116 KB Output is correct
46 Incorrect 8 ms 12092 KB Output isn't correct
47 Incorrect 7 ms 12116 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 7 ms 12092 KB Output is correct
51 Correct 6 ms 12128 KB Output is correct
52 Correct 6 ms 12116 KB Output is correct
53 Correct 6 ms 12116 KB Output is correct
54 Incorrect 6 ms 12088 KB Output isn't correct