# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
255646 |
2020-08-01T13:25:43 Z |
Saboon |
Pipes (BOI13_pipes) |
C++14 |
|
111 ms |
27764 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
vector<pair<int,int>> g[maxn];
int h[maxn], up[maxn];
ll x[maxn], w[maxn];
vector<int> cyc;
bool mark[maxn];
void DFS(int v, int idx = -1){
for (auto [u,i] : g[v]){
if (i == idx or h[u] != -1)
continue;
h[u] = h[v] + 1;
DFS(u,i);
x[v] -= w[i] / 2;
}
if (!mark[v] and idx != -1){
w[idx] = 2 * x[v];
x[v] = 0;
}
assert(x[v] == 0);
}
void dfs(int v){
up[v] = h[v];
for (auto [u,i] : g[v]){
if (h[u] == -1){
h[u] = h[v] + 1;
dfs(u);
up[v] = min(up[v], up[u]);
}
else if (h[u] != h[v]-1){
if (h[u] % 2 != h[v] % 2){
cout << 0 << endl;
exit(0);
}
up[v] = min(up[v], h[u]);
}
}
if (up[v] < h[v]){
mark[v] = 1;
cyc.push_back(v);
}
}
int main(){
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
if (m > n){
cout << 0 << endl;
exit(0);
}
for (int i = 1; i <= n; i++)
cin >> x[i];
for (int i = 0; i < m; i++){
int v, u;
cin >> v >> u;
g[v].push_back({u,i});
g[u].push_back({v,i});
}
memset(h, -1, sizeof h);
h[1] = 0;
dfs(1);
memset(h, -1, sizeof h);
int root = 1;
if (!cyc.empty())
root = cyc[0];
DFS(root);
for (int i = 0; i < m; i++)
cout << w[i] << '\n';
}
Compilation message
pipes.cpp: In function 'void DFS(int, int)':
pipes.cpp:17:12: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
for (auto [u,i] : g[v]){
^
pipes.cpp: In function 'void dfs(int)':
pipes.cpp:33:12: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
for (auto [u,i] : g[v]){
^
pipes.cpp:33:16: warning: unused variable 'i' [-Wunused-variable]
for (auto [u,i] : g[v]){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3072 KB |
Output is correct |
2 |
Correct |
2 ms |
3072 KB |
Output is correct |
3 |
Correct |
4 ms |
3200 KB |
Output is correct |
4 |
Correct |
77 ms |
10744 KB |
Output is correct |
5 |
Correct |
3 ms |
3072 KB |
Output is correct |
6 |
Correct |
2 ms |
3072 KB |
Output is correct |
7 |
Correct |
2 ms |
3072 KB |
Output is correct |
8 |
Correct |
3 ms |
3072 KB |
Output is correct |
9 |
Correct |
3 ms |
3200 KB |
Output is correct |
10 |
Correct |
3 ms |
3200 KB |
Output is correct |
11 |
Correct |
3 ms |
3200 KB |
Output is correct |
12 |
Correct |
3 ms |
3200 KB |
Output is correct |
13 |
Correct |
66 ms |
9208 KB |
Output is correct |
14 |
Correct |
83 ms |
10360 KB |
Output is correct |
15 |
Correct |
80 ms |
10744 KB |
Output is correct |
16 |
Correct |
64 ms |
9592 KB |
Output is correct |
17 |
Correct |
79 ms |
10744 KB |
Output is correct |
18 |
Correct |
95 ms |
11000 KB |
Output is correct |
19 |
Correct |
111 ms |
12540 KB |
Output is correct |
20 |
Correct |
2 ms |
3072 KB |
Output is correct |
21 |
Correct |
3 ms |
3200 KB |
Output is correct |
22 |
Correct |
87 ms |
10744 KB |
Output is correct |
23 |
Correct |
66 ms |
9208 KB |
Output is correct |
24 |
Correct |
87 ms |
10872 KB |
Output is correct |
25 |
Correct |
62 ms |
9464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
6144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Runtime error |
6 ms |
6272 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Correct |
59 ms |
11000 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
3 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Runtime error |
6 ms |
6144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
6 ms |
6144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Correct |
2 ms |
3072 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
2 ms |
2688 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Runtime error |
7 ms |
6080 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Runtime error |
6 ms |
6272 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
16 |
Runtime error |
6 ms |
6272 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Correct |
2 ms |
3200 KB |
Output is correct |
18 |
Correct |
2 ms |
2688 KB |
Output is correct |
19 |
Correct |
2 ms |
2688 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
21 |
Correct |
2 ms |
2688 KB |
Output is correct |
22 |
Runtime error |
6 ms |
6272 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
23 |
Runtime error |
69 ms |
22000 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
24 |
Runtime error |
110 ms |
24440 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
25 |
Correct |
63 ms |
11000 KB |
Output is correct |
26 |
Correct |
2 ms |
2688 KB |
Output is correct |
27 |
Correct |
2 ms |
2688 KB |
Output is correct |
28 |
Correct |
2 ms |
2688 KB |
Output is correct |
29 |
Correct |
2 ms |
2688 KB |
Output is correct |
30 |
Runtime error |
92 ms |
27380 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
31 |
Runtime error |
91 ms |
27504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
32 |
Runtime error |
78 ms |
21112 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
33 |
Correct |
61 ms |
11768 KB |
Output is correct |
34 |
Correct |
2 ms |
2688 KB |
Output is correct |
35 |
Correct |
2 ms |
2688 KB |
Output is correct |
36 |
Correct |
2 ms |
2688 KB |
Output is correct |
37 |
Correct |
2 ms |
2688 KB |
Output is correct |
38 |
Runtime error |
85 ms |
26100 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
39 |
Runtime error |
78 ms |
20344 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
40 |
Runtime error |
86 ms |
24056 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
41 |
Correct |
66 ms |
13176 KB |
Output is correct |
42 |
Correct |
2 ms |
2688 KB |
Output is correct |
43 |
Correct |
2 ms |
2688 KB |
Output is correct |
44 |
Correct |
2 ms |
2688 KB |
Output is correct |
45 |
Correct |
2 ms |
2688 KB |
Output is correct |
46 |
Runtime error |
90 ms |
27764 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
47 |
Runtime error |
83 ms |
24184 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
48 |
Runtime error |
97 ms |
27240 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
49 |
Correct |
64 ms |
9848 KB |
Output is correct |
50 |
Correct |
2 ms |
2688 KB |
Output is correct |
51 |
Correct |
2 ms |
2688 KB |
Output is correct |
52 |
Correct |
2 ms |
2688 KB |
Output is correct |
53 |
Correct |
2 ms |
2688 KB |
Output is correct |
54 |
Runtime error |
92 ms |
26296 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |