답안 #84243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
84243 2018-11-14T02:57:47 Z aome Pipes (BOI13_pipes) C++17
74.0741 / 100
278 ms 30272 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;
            }
        }
        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:56: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 2724 KB Output is correct
2 Correct 4 ms 2812 KB Output is correct
3 Correct 5 ms 3012 KB Output is correct
4 Correct 85 ms 11040 KB Output is correct
5 Correct 4 ms 11040 KB Output is correct
6 Correct 4 ms 11040 KB Output is correct
7 Correct 4 ms 11040 KB Output is correct
8 Correct 4 ms 11040 KB Output is correct
9 Correct 4 ms 11040 KB Output is correct
10 Correct 4 ms 11040 KB Output is correct
11 Correct 4 ms 11040 KB Output is correct
12 Correct 4 ms 11040 KB Output is correct
13 Correct 58 ms 11040 KB Output is correct
14 Correct 83 ms 11040 KB Output is correct
15 Correct 82 ms 11228 KB Output is correct
16 Correct 73 ms 11228 KB Output is correct
17 Correct 101 ms 11252 KB Output is correct
18 Correct 84 ms 11252 KB Output is correct
19 Correct 92 ms 11252 KB Output is correct
20 Correct 4 ms 11252 KB Output is correct
21 Correct 5 ms 11252 KB Output is correct
22 Correct 76 ms 11344 KB Output is correct
23 Correct 61 ms 11344 KB Output is correct
24 Correct 80 ms 11344 KB Output is correct
25 Correct 62 ms 11344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 11344 KB Output isn't correct
2 Incorrect 5 ms 11344 KB Output isn't correct
3 Correct 85 ms 11476 KB Output is correct
4 Correct 67 ms 11476 KB Output is correct
5 Correct 67 ms 11476 KB Output is correct
6 Correct 267 ms 30184 KB Output is correct
7 Incorrect 4 ms 30184 KB Output isn't correct
8 Incorrect 4 ms 30184 KB Output isn't correct
9 Correct 4 ms 30184 KB Output is correct
10 Correct 4 ms 30184 KB Output is correct
11 Correct 4 ms 30184 KB Output is correct
12 Correct 4 ms 30184 KB Output is correct
13 Correct 4 ms 30184 KB Output is correct
14 Incorrect 4 ms 30184 KB Output isn't correct
15 Incorrect 5 ms 30184 KB Output isn't correct
16 Incorrect 5 ms 30184 KB Output isn't correct
17 Correct 4 ms 30184 KB Output is correct
18 Correct 4 ms 30184 KB Output is correct
19 Correct 4 ms 30184 KB Output is correct
20 Correct 4 ms 30184 KB Output is correct
21 Correct 7 ms 30184 KB Output is correct
22 Incorrect 4 ms 30184 KB Output isn't correct
23 Incorrect 78 ms 30184 KB Output isn't correct
24 Incorrect 76 ms 30184 KB Output isn't correct
25 Correct 76 ms 30184 KB Output is correct
26 Correct 65 ms 30184 KB Output is correct
27 Correct 60 ms 30184 KB Output is correct
28 Correct 74 ms 30184 KB Output is correct
29 Correct 230 ms 30184 KB Output is correct
30 Incorrect 76 ms 30184 KB Output isn't correct
31 Incorrect 95 ms 30184 KB Output isn't correct
32 Incorrect 95 ms 30184 KB Output isn't correct
33 Correct 87 ms 30184 KB Output is correct
34 Correct 62 ms 30184 KB Output is correct
35 Correct 62 ms 30184 KB Output is correct
36 Correct 67 ms 30184 KB Output is correct
37 Correct 278 ms 30272 KB Output is correct
38 Incorrect 95 ms 30272 KB Output isn't correct
39 Incorrect 88 ms 30272 KB Output isn't correct
40 Incorrect 89 ms 30272 KB Output isn't correct
41 Correct 88 ms 30272 KB Output is correct
42 Correct 59 ms 30272 KB Output is correct
43 Correct 60 ms 30272 KB Output is correct
44 Correct 61 ms 30272 KB Output is correct
45 Correct 266 ms 30272 KB Output is correct
46 Incorrect 86 ms 30272 KB Output isn't correct
47 Incorrect 111 ms 30272 KB Output isn't correct
48 Incorrect 93 ms 30272 KB Output isn't correct
49 Correct 68 ms 30272 KB Output is correct
50 Correct 72 ms 30272 KB Output is correct
51 Correct 67 ms 30272 KB Output is correct
52 Correct 63 ms 30272 KB Output is correct
53 Correct 246 ms 30272 KB Output is correct
54 Incorrect 88 ms 30272 KB Output isn't correct