Submission #84242

# Submission time Handle Problem Language Result Execution time Memory
84242 2018-11-14T02:56:50 Z aome Pipes (BOI13_pipes) C++17
74.0741 / 100
247 ms 17704 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, 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 || ans[mv.back().second] % 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;
                         ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2684 KB Output is correct
2 Correct 4 ms 2828 KB Output is correct
3 Correct 4 ms 2872 KB Output is correct
4 Correct 91 ms 8532 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 4 ms 8532 KB Output is correct
7 Correct 5 ms 8532 KB Output is correct
8 Correct 4 ms 8532 KB Output is correct
9 Correct 4 ms 8532 KB Output is correct
10 Correct 4 ms 8532 KB Output is correct
11 Correct 5 ms 8532 KB Output is correct
12 Correct 4 ms 8532 KB Output is correct
13 Correct 61 ms 8532 KB Output is correct
14 Correct 77 ms 8532 KB Output is correct
15 Correct 84 ms 8688 KB Output is correct
16 Correct 58 ms 8688 KB Output is correct
17 Correct 87 ms 8704 KB Output is correct
18 Correct 95 ms 8704 KB Output is correct
19 Correct 78 ms 8704 KB Output is correct
20 Correct 4 ms 8704 KB Output is correct
21 Correct 4 ms 8704 KB Output is correct
22 Correct 75 ms 8704 KB Output is correct
23 Correct 57 ms 8704 KB Output is correct
24 Correct 72 ms 8704 KB Output is correct
25 Correct 62 ms 8704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 8704 KB Output isn't correct
2 Incorrect 4 ms 8704 KB Output isn't correct
3 Correct 63 ms 8704 KB Output is correct
4 Correct 61 ms 8704 KB Output is correct
5 Correct 61 ms 8704 KB Output is correct
6 Correct 235 ms 17704 KB Output is correct
7 Incorrect 4 ms 17704 KB Output isn't correct
8 Incorrect 4 ms 17704 KB Output isn't correct
9 Correct 5 ms 17704 KB Output is correct
10 Correct 4 ms 17704 KB Output is correct
11 Correct 4 ms 17704 KB Output is correct
12 Correct 4 ms 17704 KB Output is correct
13 Correct 4 ms 17704 KB Output is correct
14 Incorrect 4 ms 17704 KB Output isn't correct
15 Incorrect 4 ms 17704 KB Output isn't correct
16 Incorrect 6 ms 17704 KB Output isn't correct
17 Correct 6 ms 17704 KB Output is correct
18 Correct 4 ms 17704 KB Output is correct
19 Correct 4 ms 17704 KB Output is correct
20 Correct 5 ms 17704 KB Output is correct
21 Correct 5 ms 17704 KB Output is correct
22 Incorrect 4 ms 17704 KB Output isn't correct
23 Incorrect 64 ms 17704 KB Output isn't correct
24 Incorrect 71 ms 17704 KB Output isn't correct
25 Correct 60 ms 17704 KB Output is correct
26 Correct 64 ms 17704 KB Output is correct
27 Correct 53 ms 17704 KB Output is correct
28 Correct 67 ms 17704 KB Output is correct
29 Correct 200 ms 17704 KB Output is correct
30 Incorrect 87 ms 17704 KB Output isn't correct
31 Incorrect 79 ms 17704 KB Output isn't correct
32 Incorrect 76 ms 17704 KB Output isn't correct
33 Correct 71 ms 17704 KB Output is correct
34 Correct 75 ms 17704 KB Output is correct
35 Correct 71 ms 17704 KB Output is correct
36 Correct 61 ms 17704 KB Output is correct
37 Correct 247 ms 17704 KB Output is correct
38 Incorrect 86 ms 17704 KB Output isn't correct
39 Incorrect 81 ms 17704 KB Output isn't correct
40 Incorrect 78 ms 17704 KB Output isn't correct
41 Correct 79 ms 17704 KB Output is correct
42 Correct 53 ms 17704 KB Output is correct
43 Correct 63 ms 17704 KB Output is correct
44 Correct 62 ms 17704 KB Output is correct
45 Correct 184 ms 17704 KB Output is correct
46 Incorrect 65 ms 17704 KB Output isn't correct
47 Incorrect 71 ms 17704 KB Output isn't correct
48 Incorrect 74 ms 17704 KB Output isn't correct
49 Correct 56 ms 17704 KB Output is correct
50 Correct 58 ms 17704 KB Output is correct
51 Correct 57 ms 17704 KB Output is correct
52 Correct 54 ms 17704 KB Output is correct
53 Correct 196 ms 17704 KB Output is correct
54 Incorrect 61 ms 17704 KB Output isn't correct