# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
80069 | 2018-10-18T16:42:00 Z | win11905 | Pipes (BOI13_pipes) | C++11 | 211 ms | 36456 KB |
#include <bits/stdc++.h> using namespace std; const int N = 1e5+5; int n, m, s[N], t[N]; int A[N], deg[N]; int ans[N]; set<int> g[N]; void answer() { for(int i = 0; i < m; ++i) printf("%d\n", ans[i]); exit(0); } queue<int> Q; void solve() { while(!Q.empty()) { int u = Q.front(); Q.pop(); for(int x : g[u]) { int v = u ^ s[x] ^ t[x]; g[v].erase(x); A[v] -= A[u]; ans[x] = A[u] << 1; if(g[v].size() == 1) Q.emplace(v); } g[u].clear(); } } int cnt = 0; void dfs(int u, int p) { static int idx = 0; static int sum = 0; idx++; if(idx & 1) sum += A[u]; else sum -= A[u]; int z = -1; for(auto i : g[u]) { int v = u ^ s[i] ^ t[i]; if(v != p) { if(cnt == idx) { ans[i] = sum; A[u] -= sum / 2, A[v] -= sum / 2; z = i; break; } dfs(v, u); } } if(cnt == idx) { int v = u ^ s[z] ^ t[z]; g[v].erase(z), g[u].erase(z); Q.emplace(u); } } int main() { scanf("%d %d", &n, &m); if(n < m) return puts("0"), 0; for(int i = 1; i <= n; ++i) scanf("%d", A+i); for(int i = 0; i < m; ++i) { scanf("%d %d", s+i, t+i); g[s[i]].emplace(i), g[t[i]].emplace(i); deg[s[i]]++, deg[t[i]]++; } for(int i = 1; i <= n; ++i) if(deg[i] == 1) Q.emplace(i); solve(); if(n == m+1) answer(); for(int i = 1; i <= n; ++i) if(g[i].size()) cnt++; if(cnt % 2 == 0) return puts("0"), 0; for(int i = 1; i <= n; ++i) { if(g[i].size()) dfs(i, i); solve(); } answer(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 5112 KB | Output is correct |
2 | Correct | 6 ms | 5228 KB | Output is correct |
3 | Correct | 7 ms | 5228 KB | Output is correct |
4 | Correct | 169 ms | 18484 KB | Output is correct |
5 | Correct | 6 ms | 18484 KB | Output is correct |
6 | Correct | 7 ms | 18484 KB | Output is correct |
7 | Correct | 6 ms | 18484 KB | Output is correct |
8 | Correct | 6 ms | 18484 KB | Output is correct |
9 | Correct | 7 ms | 18484 KB | Output is correct |
10 | Correct | 7 ms | 18484 KB | Output is correct |
11 | Correct | 8 ms | 18484 KB | Output is correct |
12 | Correct | 7 ms | 18484 KB | Output is correct |
13 | Correct | 136 ms | 18484 KB | Output is correct |
14 | Correct | 158 ms | 20924 KB | Output is correct |
15 | Correct | 173 ms | 23332 KB | Output is correct |
16 | Correct | 144 ms | 23332 KB | Output is correct |
17 | Correct | 184 ms | 26000 KB | Output is correct |
18 | Correct | 191 ms | 27740 KB | Output is correct |
19 | Correct | 146 ms | 29140 KB | Output is correct |
20 | Correct | 6 ms | 29140 KB | Output is correct |
21 | Correct | 7 ms | 29140 KB | Output is correct |
22 | Correct | 171 ms | 29480 KB | Output is correct |
23 | Correct | 133 ms | 29480 KB | Output is correct |
24 | Correct | 168 ms | 29480 KB | Output is correct |
25 | Correct | 147 ms | 29480 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 29480 KB | Output is correct |
2 | Correct | 7 ms | 29480 KB | Output is correct |
3 | Correct | 129 ms | 29480 KB | Output is correct |
4 | Correct | 6 ms | 29480 KB | Output is correct |
5 | Correct | 6 ms | 29480 KB | Output is correct |
6 | Correct | 6 ms | 29480 KB | Output is correct |
7 | Correct | 6 ms | 29480 KB | Output is correct |
8 | Correct | 6 ms | 29480 KB | Output is correct |
9 | Correct | 6 ms | 29480 KB | Output is correct |
10 | Correct | 6 ms | 29480 KB | Output is correct |
11 | Correct | 6 ms | 29480 KB | Output is correct |
12 | Correct | 6 ms | 29480 KB | Output is correct |
13 | Correct | 6 ms | 29480 KB | Output is correct |
14 | Correct | 6 ms | 29480 KB | Output is correct |
15 | Correct | 7 ms | 29480 KB | Output is correct |
16 | Correct | 7 ms | 29480 KB | Output is correct |
17 | Correct | 7 ms | 29480 KB | Output is correct |
18 | Correct | 6 ms | 29480 KB | Output is correct |
19 | Correct | 6 ms | 29480 KB | Output is correct |
20 | Correct | 6 ms | 29480 KB | Output is correct |
21 | Correct | 6 ms | 29480 KB | Output is correct |
22 | Correct | 7 ms | 29480 KB | Output is correct |
23 | Correct | 152 ms | 31400 KB | Output is correct |
24 | Correct | 206 ms | 33708 KB | Output is correct |
25 | Correct | 161 ms | 33708 KB | Output is correct |
26 | Correct | 6 ms | 33708 KB | Output is correct |
27 | Correct | 6 ms | 33708 KB | Output is correct |
28 | Correct | 6 ms | 33708 KB | Output is correct |
29 | Correct | 6 ms | 33708 KB | Output is correct |
30 | Correct | 175 ms | 33708 KB | Output is correct |
31 | Correct | 201 ms | 36456 KB | Output is correct |
32 | Correct | 175 ms | 36456 KB | Output is correct |
33 | Correct | 126 ms | 36456 KB | Output is correct |
34 | Correct | 6 ms | 36456 KB | Output is correct |
35 | Correct | 6 ms | 36456 KB | Output is correct |
36 | Correct | 6 ms | 36456 KB | Output is correct |
37 | Correct | 6 ms | 36456 KB | Output is correct |
38 | Correct | 194 ms | 36456 KB | Output is correct |
39 | Correct | 179 ms | 36456 KB | Output is correct |
40 | Correct | 185 ms | 36456 KB | Output is correct |
41 | Correct | 110 ms | 36456 KB | Output is correct |
42 | Correct | 6 ms | 36456 KB | Output is correct |
43 | Correct | 6 ms | 36456 KB | Output is correct |
44 | Correct | 6 ms | 36456 KB | Output is correct |
45 | Correct | 6 ms | 36456 KB | Output is correct |
46 | Correct | 173 ms | 36456 KB | Output is correct |
47 | Correct | 210 ms | 36456 KB | Output is correct |
48 | Correct | 211 ms | 36456 KB | Output is correct |
49 | Correct | 160 ms | 36456 KB | Output is correct |
50 | Correct | 8 ms | 36456 KB | Output is correct |
51 | Correct | 6 ms | 36456 KB | Output is correct |
52 | Correct | 6 ms | 36456 KB | Output is correct |
53 | Correct | 6 ms | 36456 KB | Output is correct |
54 | Correct | 160 ms | 36456 KB | Output is correct |