Submission #84249

# Submission time Handle Problem Language Result Execution time Memory
84249 2018-11-14T03:06:34 Z aome Pipes (BOI13_pipes) C++17
100 / 100
269 ms 30356 KB
#include<bits/stdc++.h>
#define int long long
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];

signed 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;
            }
        }
        for (auto p : adj[u]){
            int v = p.first, id = p.second;
            if (dead[v] && v != i) 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:61: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 2680 KB Output is correct
2 Correct 4 ms 2684 KB Output is correct
3 Correct 5 ms 2856 KB Output is correct
4 Correct 97 ms 10948 KB Output is correct
5 Correct 4 ms 10948 KB Output is correct
6 Correct 4 ms 10948 KB Output is correct
7 Correct 4 ms 10948 KB Output is correct
8 Correct 4 ms 10948 KB Output is correct
9 Correct 5 ms 10948 KB Output is correct
10 Correct 5 ms 10948 KB Output is correct
11 Correct 5 ms 10948 KB Output is correct
12 Correct 5 ms 10948 KB Output is correct
13 Correct 70 ms 10948 KB Output is correct
14 Correct 90 ms 10948 KB Output is correct
15 Correct 83 ms 11196 KB Output is correct
16 Correct 80 ms 11196 KB Output is correct
17 Correct 101 ms 11196 KB Output is correct
18 Correct 82 ms 11204 KB Output is correct
19 Correct 112 ms 11204 KB Output is correct
20 Correct 4 ms 11204 KB Output is correct
21 Correct 6 ms 11204 KB Output is correct
22 Correct 84 ms 11348 KB Output is correct
23 Correct 57 ms 11348 KB Output is correct
24 Correct 79 ms 11348 KB Output is correct
25 Correct 67 ms 11348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11348 KB Output is correct
2 Correct 6 ms 11348 KB Output is correct
3 Correct 92 ms 11464 KB Output is correct
4 Correct 91 ms 11464 KB Output is correct
5 Correct 66 ms 11464 KB Output is correct
6 Correct 269 ms 30332 KB Output is correct
7 Correct 4 ms 30332 KB Output is correct
8 Correct 4 ms 30332 KB Output is correct
9 Correct 4 ms 30332 KB Output is correct
10 Correct 4 ms 30332 KB Output is correct
11 Correct 4 ms 30332 KB Output is correct
12 Correct 4 ms 30332 KB Output is correct
13 Correct 4 ms 30332 KB Output is correct
14 Correct 4 ms 30332 KB Output is correct
15 Correct 4 ms 30332 KB Output is correct
16 Correct 4 ms 30332 KB Output is correct
17 Correct 4 ms 30332 KB Output is correct
18 Correct 4 ms 30332 KB Output is correct
19 Correct 4 ms 30332 KB Output is correct
20 Correct 4 ms 30332 KB Output is correct
21 Correct 5 ms 30332 KB Output is correct
22 Correct 5 ms 30332 KB Output is correct
23 Correct 68 ms 30332 KB Output is correct
24 Correct 87 ms 30332 KB Output is correct
25 Correct 68 ms 30332 KB Output is correct
26 Correct 63 ms 30332 KB Output is correct
27 Correct 67 ms 30332 KB Output is correct
28 Correct 63 ms 30332 KB Output is correct
29 Correct 215 ms 30332 KB Output is correct
30 Correct 84 ms 30332 KB Output is correct
31 Correct 81 ms 30332 KB Output is correct
32 Correct 85 ms 30332 KB Output is correct
33 Correct 70 ms 30332 KB Output is correct
34 Correct 63 ms 30332 KB Output is correct
35 Correct 64 ms 30332 KB Output is correct
36 Correct 64 ms 30332 KB Output is correct
37 Correct 259 ms 30356 KB Output is correct
38 Correct 81 ms 30356 KB Output is correct
39 Correct 77 ms 30356 KB Output is correct
40 Correct 81 ms 30356 KB Output is correct
41 Correct 70 ms 30356 KB Output is correct
42 Correct 65 ms 30356 KB Output is correct
43 Correct 69 ms 30356 KB Output is correct
44 Correct 63 ms 30356 KB Output is correct
45 Correct 200 ms 30356 KB Output is correct
46 Correct 88 ms 30356 KB Output is correct
47 Correct 92 ms 30356 KB Output is correct
48 Correct 114 ms 30356 KB Output is correct
49 Correct 64 ms 30356 KB Output is correct
50 Correct 82 ms 30356 KB Output is correct
51 Correct 113 ms 30356 KB Output is correct
52 Correct 62 ms 30356 KB Output is correct
53 Correct 235 ms 30356 KB Output is correct
54 Correct 81 ms 30356 KB Output is correct