답안 #84240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
84240 2018-11-14T02:55:16 Z aome Pipes (BOI13_pipes) C++17
74.0741 / 100
267 ms 20572 KB
#include<bits/stdc++.h>
const int N = 1e5 + 5;
using namespace std;

typedef pair <int, int> ii;
vector <ii> adj[N];

int n, m, cnt[N], ans[5*N], a[N];
bool dead[N];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        adj[u].push_back(ii(v, i));
        adj[v].push_back(ii(u, i));
        cnt[u]++; cnt[v]++;
    }
    queue <int> mq;
    for (int i = 1; i <= n; i++) if (cnt[i] <= 1) mq.push(i);
    while (mq.size()){
        int u = mq.front(); mq.pop();
        dead[u] = true;
        for (auto p : adj[u]){
            int v = p.first, id = p.second;
            cnt[v]--;
            if (dead[v]) continue;
            ans[id] = a[u];
            a[v] -= a[u];
            a[u] = 0;
            if (cnt[v] == 1) mq.push(v);
        }
        if (a[u]) return cout << 0, 0;
    }
    for (int i = 1; i <= n; i++) if (cnt[i] >= 3) return cout << 0, 0;
    for (int i = 1; i <= n; i++){
        if (dead[i]) continue;
        vector <ii> mv;
        int u = i, cnt = 0, sum = 0, cur = 0;
        while (!dead[u]){
            dead[u] = true; cnt++;
            for (auto p : adj[u]){
                int v = p.first, id = p.second;
                if (dead[v]) continue;
                ans[id] = a[u] - cur; cur = ans[id];
                u = v; mv.push_back(ii(u, id));
                break;
            }
            if (cnt % 2 == 0 || sum % 2 == 1) return cout << 0, 0;
        }
        cur = ans[mv.back().second] / 2;
        for (int i = 0; i < mv.size(); i++) ans[mv[i].second] -= cur, cur = -cur;
    }
    for (int i = 1; i <= m; i++) cout << ans[i] * 2 << "\n";
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:55:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < mv.size(); i++) ans[mv[i].second] -= cur, cur = -cur;
                         ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2812 KB Output is correct
3 Correct 4 ms 2888 KB Output is correct
4 Correct 76 ms 9028 KB Output is correct
5 Correct 4 ms 9028 KB Output is correct
6 Correct 4 ms 9028 KB Output is correct
7 Correct 4 ms 9028 KB Output is correct
8 Correct 4 ms 9028 KB Output is correct
9 Correct 4 ms 9028 KB Output is correct
10 Correct 4 ms 9028 KB Output is correct
11 Correct 4 ms 9028 KB Output is correct
12 Correct 4 ms 9028 KB Output is correct
13 Correct 70 ms 9028 KB Output is correct
14 Correct 74 ms 9028 KB Output is correct
15 Correct 73 ms 9124 KB Output is correct
16 Correct 59 ms 9124 KB Output is correct
17 Correct 74 ms 9160 KB Output is correct
18 Correct 78 ms 9792 KB Output is correct
19 Correct 87 ms 9792 KB Output is correct
20 Correct 4 ms 9792 KB Output is correct
21 Correct 4 ms 9792 KB Output is correct
22 Correct 73 ms 9792 KB Output is correct
23 Correct 59 ms 9792 KB Output is correct
24 Correct 74 ms 9860 KB Output is correct
25 Correct 63 ms 9860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 9860 KB Output isn't correct
2 Incorrect 5 ms 9860 KB Output isn't correct
3 Correct 58 ms 9860 KB Output is correct
4 Correct 60 ms 9860 KB Output is correct
5 Correct 64 ms 9860 KB Output is correct
6 Correct 267 ms 19132 KB Output is correct
7 Incorrect 4 ms 19132 KB Output isn't correct
8 Incorrect 4 ms 19132 KB Output isn't correct
9 Correct 4 ms 19132 KB Output is correct
10 Correct 4 ms 19132 KB Output is correct
11 Correct 4 ms 19132 KB Output is correct
12 Correct 4 ms 19132 KB Output is correct
13 Correct 4 ms 19132 KB Output is correct
14 Incorrect 4 ms 19132 KB Output isn't correct
15 Incorrect 4 ms 19132 KB Output isn't correct
16 Incorrect 4 ms 19132 KB Output isn't correct
17 Correct 4 ms 19132 KB Output is correct
18 Correct 4 ms 19132 KB Output is correct
19 Correct 4 ms 19132 KB Output is correct
20 Correct 4 ms 19132 KB Output is correct
21 Correct 5 ms 19132 KB Output is correct
22 Incorrect 4 ms 19132 KB Output isn't correct
23 Incorrect 48 ms 19132 KB Output isn't correct
24 Incorrect 83 ms 19132 KB Output isn't correct
25 Correct 62 ms 19132 KB Output is correct
26 Correct 65 ms 19132 KB Output is correct
27 Correct 56 ms 19132 KB Output is correct
28 Correct 66 ms 19132 KB Output is correct
29 Correct 211 ms 19132 KB Output is correct
30 Incorrect 70 ms 19132 KB Output isn't correct
31 Incorrect 60 ms 19132 KB Output isn't correct
32 Incorrect 67 ms 19132 KB Output isn't correct
33 Correct 67 ms 19132 KB Output is correct
34 Correct 60 ms 19132 KB Output is correct
35 Correct 62 ms 19132 KB Output is correct
36 Correct 67 ms 19132 KB Output is correct
37 Correct 253 ms 19132 KB Output is correct
38 Incorrect 88 ms 19132 KB Output isn't correct
39 Incorrect 68 ms 19132 KB Output isn't correct
40 Incorrect 70 ms 19132 KB Output isn't correct
41 Correct 61 ms 19132 KB Output is correct
42 Correct 57 ms 19132 KB Output is correct
43 Correct 58 ms 19132 KB Output is correct
44 Correct 67 ms 19132 KB Output is correct
45 Correct 212 ms 20572 KB Output is correct
46 Incorrect 68 ms 20572 KB Output isn't correct
47 Incorrect 65 ms 20572 KB Output isn't correct
48 Incorrect 64 ms 20572 KB Output isn't correct
49 Correct 62 ms 20572 KB Output is correct
50 Correct 94 ms 20572 KB Output is correct
51 Correct 65 ms 20572 KB Output is correct
52 Correct 59 ms 20572 KB Output is correct
53 Correct 201 ms 20572 KB Output is correct
54 Incorrect 60 ms 20572 KB Output isn't correct