# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
319025 |
2020-11-03T18:26:48 Z |
rqi |
Pipes (BOI13_pipes) |
C++14 |
|
385 ms |
35940 KB |
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
#define mp make_pair
#define f first
#define s second
#define pb push_back
struct DSU{
vi e;
void init(int n){
e = vi(n, -1);
}
int get(int a){
if(e[a] < 0) return a;
e[a] = get(e[a]);
return e[a];
}
bool unite(int a, int b){
a = get(a);
b = get(b);
if(a == b) return 0;
if(-e[a] < -e[b]) swap(a, b);
e[b] = a;
return 1;
}
};
const int mx = 500005;
const int mx1 = 100005;
int N, M;
ll c[mx1];
ll origc[mx1];
int u[mx];
int v[mx];
ll x[mx];
bool inTree[mx1];
vpi adj[mx1];
int depth[mx1];
void genTree(int node, int prv = -1, int d = 0){
depth[node] = d;
for(auto u: adj[node]){
if(u.f == prv) continue;
genTree(u.f, node, d+1);
ll val = c[u.f];
x[u.s]+=val;
c[u.f]-=val;
c[node]-=val;
}
}
int main(){
cin >> N >> M;
DSU dsu;
dsu.init(N+5);
for(int i = 1; i <= N; i++){
cin >> c[i];
origc[i] = c[i];
}
for(int i = 1; i <= M; i++){
cin >> u[i] >> v[i];
if(dsu.unite(u[i], v[i])){
inTree[i] = 1;
adj[u[i]].pb(mp(v[i], i));
adj[v[i]].pb(mp(u[i], i));
}
}
genTree(1);
if(M == N-1){ //Good
if(c[1] != 0){
assert(0==1);
cout << 0 << "\n";
return 0;
}
for(int i = 1; i <= M; i++){
cout << 2*x[i] << "\n";
}
return 0;
}
if(M >= N+1){
cout << 0 << "\n";
assert(0==1);
return 0;
}
for(int i = 1; i <= M; i++){
if(inTree[i]) continue;
if(depth[u[i]] % 2 != depth[v[i]] % 2){
cout << 0 << "\n";
return 0;
}
for(int j = 1; j <= M; j++){
x[j] = 0;
}
x[i] = c[1]/2;
origc[u[i]]-=x[i];
origc[v[i]]-=x[i];
for(int j = 1; j <= N; j++){
c[j] = origc[j];
}
genTree(1);
}
for(int i = 1; i <= M; i++){
cout << 2*x[i] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
3 ms |
2796 KB |
Output is correct |
4 |
Correct |
139 ms |
12128 KB |
Output is correct |
5 |
Correct |
2 ms |
2668 KB |
Output is correct |
6 |
Correct |
2 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
2668 KB |
Output is correct |
8 |
Correct |
2 ms |
2796 KB |
Output is correct |
9 |
Correct |
3 ms |
2796 KB |
Output is correct |
10 |
Correct |
3 ms |
2796 KB |
Output is correct |
11 |
Correct |
3 ms |
2796 KB |
Output is correct |
12 |
Correct |
3 ms |
2796 KB |
Output is correct |
13 |
Correct |
105 ms |
10212 KB |
Output is correct |
14 |
Correct |
130 ms |
11676 KB |
Output is correct |
15 |
Correct |
140 ms |
12232 KB |
Output is correct |
16 |
Correct |
113 ms |
10724 KB |
Output is correct |
17 |
Correct |
136 ms |
12132 KB |
Output is correct |
18 |
Correct |
140 ms |
12260 KB |
Output is correct |
19 |
Correct |
143 ms |
16272 KB |
Output is correct |
20 |
Correct |
3 ms |
2700 KB |
Output is correct |
21 |
Correct |
3 ms |
2796 KB |
Output is correct |
22 |
Correct |
139 ms |
12264 KB |
Output is correct |
23 |
Correct |
106 ms |
10212 KB |
Output is correct |
24 |
Correct |
137 ms |
12260 KB |
Output is correct |
25 |
Correct |
112 ms |
10596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2668 KB |
Output is correct |
2 |
Incorrect |
3 ms |
2924 KB |
Output isn't correct |
3 |
Correct |
122 ms |
13796 KB |
Output is correct |
4 |
Runtime error |
145 ms |
28008 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
5 |
Runtime error |
133 ms |
21860 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
6 |
Runtime error |
385 ms |
34660 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
7 |
Correct |
2 ms |
2668 KB |
Output is correct |
8 |
Correct |
3 ms |
2668 KB |
Output is correct |
9 |
Correct |
2 ms |
2668 KB |
Output is correct |
10 |
Runtime error |
6 ms |
5356 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
11 |
Runtime error |
6 ms |
5356 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
12 |
Runtime error |
6 ms |
5356 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
13 |
Runtime error |
6 ms |
5356 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
14 |
Correct |
2 ms |
2668 KB |
Output is correct |
15 |
Incorrect |
3 ms |
2924 KB |
Output isn't correct |
16 |
Incorrect |
3 ms |
2796 KB |
Output isn't correct |
17 |
Correct |
3 ms |
2796 KB |
Output is correct |
18 |
Runtime error |
7 ms |
5484 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
19 |
Runtime error |
7 ms |
5612 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
20 |
Runtime error |
7 ms |
5484 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
21 |
Runtime error |
9 ms |
5484 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
22 |
Incorrect |
3 ms |
2796 KB |
Output isn't correct |
23 |
Correct |
125 ms |
12628 KB |
Output is correct |
24 |
Incorrect |
161 ms |
15560 KB |
Output isn't correct |
25 |
Correct |
125 ms |
13540 KB |
Output is correct |
26 |
Runtime error |
152 ms |
32616 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
27 |
Runtime error |
152 ms |
33636 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
28 |
Runtime error |
144 ms |
21988 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
29 |
Runtime error |
333 ms |
32312 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
30 |
Incorrect |
157 ms |
18916 KB |
Output isn't correct |
31 |
Correct |
162 ms |
18276 KB |
Output is correct |
32 |
Correct |
160 ms |
13028 KB |
Output is correct |
33 |
Correct |
134 ms |
14948 KB |
Output is correct |
34 |
Runtime error |
147 ms |
31332 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
35 |
Runtime error |
148 ms |
28004 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
36 |
Runtime error |
146 ms |
21732 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
37 |
Runtime error |
383 ms |
34664 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
38 |
Incorrect |
160 ms |
14820 KB |
Output isn't correct |
39 |
Correct |
152 ms |
12644 KB |
Output is correct |
40 |
Incorrect |
158 ms |
14692 KB |
Output isn't correct |
41 |
Correct |
132 ms |
18404 KB |
Output is correct |
42 |
Runtime error |
154 ms |
35940 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
43 |
Runtime error |
148 ms |
30436 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
44 |
Runtime error |
139 ms |
21736 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
45 |
Runtime error |
307 ms |
25316 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
46 |
Correct |
168 ms |
17124 KB |
Output is correct |
47 |
Incorrect |
166 ms |
15076 KB |
Output isn't correct |
48 |
Incorrect |
168 ms |
19048 KB |
Output isn't correct |
49 |
Correct |
114 ms |
12132 KB |
Output is correct |
50 |
Runtime error |
154 ms |
30052 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
51 |
Runtime error |
149 ms |
25572 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
52 |
Runtime error |
140 ms |
24036 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
53 |
Runtime error |
329 ms |
28388 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
54 |
Correct |
159 ms |
16356 KB |
Output is correct |