답안 #673475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
673475 2022-12-20T16:41:09 Z Lobo Pipes (BOI13_pipes) C++17
30 / 100
67 ms 24400 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) {
        assert(0);
        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();
    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 12100 KB Output is correct
3 Correct 6 ms 12116 KB Output is correct
4 Correct 60 ms 20304 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 7 ms 11988 KB Output is correct
7 Correct 6 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 7 ms 12116 KB Output is correct
11 Correct 7 ms 12116 KB Output is correct
12 Correct 7 ms 12068 KB Output is correct
13 Correct 46 ms 18580 KB Output is correct
14 Correct 57 ms 19892 KB Output is correct
15 Correct 67 ms 20428 KB Output is correct
16 Correct 50 ms 19112 KB Output is correct
17 Correct 67 ms 20288 KB Output is correct
18 Correct 58 ms 20424 KB Output is correct
19 Correct 63 ms 20064 KB Output is correct
20 Correct 6 ms 11988 KB Output is correct
21 Correct 7 ms 12116 KB Output is correct
22 Correct 57 ms 20332 KB Output is correct
23 Correct 45 ms 18664 KB Output is correct
24 Correct 60 ms 20428 KB Output is correct
25 Correct 53 ms 18980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 24328 KB Execution killed with signal 6
2 Runtime error 14 ms 24292 KB Execution killed with signal 6
3 Runtime error 14 ms 24224 KB Execution killed with signal 6
4 Runtime error 16 ms 24276 KB Execution killed with signal 6
5 Runtime error 15 ms 24276 KB Execution killed with signal 6
6 Runtime error 18 ms 24276 KB Execution killed with signal 6
7 Runtime error 16 ms 24276 KB Execution killed with signal 6
8 Runtime error 17 ms 24276 KB Execution killed with signal 6
9 Runtime error 16 ms 24276 KB Execution killed with signal 6
10 Runtime error 17 ms 24308 KB Execution killed with signal 6
11 Runtime error 16 ms 24296 KB Execution killed with signal 6
12 Runtime error 15 ms 24276 KB Execution killed with signal 6
13 Runtime error 17 ms 24400 KB Execution killed with signal 6
14 Runtime error 16 ms 24276 KB Execution killed with signal 6
15 Runtime error 17 ms 24220 KB Execution killed with signal 6
16 Runtime error 15 ms 24276 KB Execution killed with signal 6
17 Runtime error 15 ms 24244 KB Execution killed with signal 6
18 Runtime error 16 ms 24264 KB Execution killed with signal 6
19 Runtime error 16 ms 24276 KB Execution killed with signal 6
20 Runtime error 16 ms 24252 KB Execution killed with signal 6
21 Runtime error 16 ms 24276 KB Execution killed with signal 6
22 Runtime error 16 ms 24272 KB Execution killed with signal 6
23 Runtime error 19 ms 24240 KB Execution killed with signal 6
24 Runtime error 16 ms 24276 KB Execution killed with signal 6
25 Runtime error 18 ms 24276 KB Execution killed with signal 6
26 Runtime error 15 ms 24328 KB Execution killed with signal 6
27 Runtime error 17 ms 24292 KB Execution killed with signal 6
28 Runtime error 16 ms 24288 KB Execution killed with signal 6
29 Runtime error 16 ms 24276 KB Execution killed with signal 6
30 Runtime error 15 ms 24276 KB Execution killed with signal 6
31 Runtime error 15 ms 24276 KB Execution killed with signal 6
32 Runtime error 16 ms 24284 KB Execution killed with signal 6
33 Runtime error 15 ms 24304 KB Execution killed with signal 6
34 Runtime error 16 ms 24276 KB Execution killed with signal 6
35 Runtime error 15 ms 24276 KB Execution killed with signal 6
36 Runtime error 15 ms 24284 KB Execution killed with signal 6
37 Runtime error 15 ms 24328 KB Execution killed with signal 6
38 Runtime error 15 ms 24276 KB Execution killed with signal 6
39 Runtime error 15 ms 24276 KB Execution killed with signal 6
40 Runtime error 17 ms 24276 KB Execution killed with signal 6
41 Runtime error 15 ms 24276 KB Execution killed with signal 6
42 Runtime error 15 ms 24276 KB Execution killed with signal 6
43 Runtime error 15 ms 24276 KB Execution killed with signal 6
44 Runtime error 15 ms 24276 KB Execution killed with signal 6
45 Runtime error 16 ms 24312 KB Execution killed with signal 6
46 Runtime error 15 ms 24220 KB Execution killed with signal 6
47 Runtime error 15 ms 24208 KB Execution killed with signal 6
48 Runtime error 16 ms 24340 KB Execution killed with signal 6
49 Runtime error 16 ms 24276 KB Execution killed with signal 6
50 Runtime error 16 ms 24276 KB Execution killed with signal 6
51 Runtime error 16 ms 24272 KB Execution killed with signal 6
52 Runtime error 16 ms 24320 KB Execution killed with signal 6
53 Runtime error 17 ms 24276 KB Execution killed with signal 6
54 Runtime error 17 ms 24276 KB Execution killed with signal 6