# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
548348 | 2022-04-13T05:11:47 Z | Amylopectin | Pipes (BOI13_pipes) | C++14 | 262 ms | 42696 KB |
#include <iostream> #include <stdio.h> #include <vector> #include <queue> using namespace std; const int mxn = 6e5 + 10; struct we { long long to,num; }; queue<long long> qu; vector<struct we> pa[mxn] = {}; long long patva[mxn] = {},nva[mxn] = {},ind[mxn] = {},u[mxn] = {},upa[mxn] = {},sta = 0,li[mxn] = {},pnu[mxn] = {}; long long re(long long cn,long long cou) { long long i,j,fn,cnu; u[cn] = 1; li[cou] = cn; for(i=0; i<pa[cn].size(); i++) { fn = pa[cn][i].to; cnu = pa[cn][i].num; if(cou > 1 && fn == li[0]) { pnu[cou] = cnu; } if(u[fn] == 1) continue; pnu[cou] = cnu; re(fn,cou+1); } return 0; } int main() { // freopen("pipes.g07-1.in","r",stdin); // freopen("ex 1.out","a",stdout); long long i,j,n,m,cn,cm,fn,fm,cou = 0,cnu,of,cyn,st,su,csu; scanf("%lld %lld",&n,&m); for(i=1; i<=n; i++) { scanf("%lld",&nva[i]); } for(j=0; j<m; j++) { scanf("%lld %lld",&cn,&cm); pa[cn].push_back({cm,j}); pa[cm].push_back({cn,j}); ind[cn] ++; ind[cm] ++; } if(m > n) { printf("0\n"); return 0; } for(i=1; i<=n; i++) { if(ind[i] == 1) { qu.push(i); u[i] = 1; cou ++; } } if(m == n-1) { while(!qu.empty()) { cn = qu.front(); qu.pop(); // of = 1; for(i=0; i<pa[cn].size(); i++) { fn = pa[cn][i].to; cnu = pa[cn][i].num; if(upa[cnu] == 1) continue; upa[cnu] = 1; // of = 0; ind[fn] --; patva[cnu] = nva[cn]; nva[fn] -= nva[cn]; if(u[fn] == 1) { if(nva[fn] != 0) { // printf("0\n"); // return 0; } } if(ind[fn] == 1) { u[fn] = 1; qu.push(fn); cou ++; } } // if(of == 1) // { // if() // } } for(i=0; i<m; i++) { printf("%lld\n",patva[i] * 2); } } else { while(!qu.empty()) { cn = qu.front(); qu.pop(); for(i=0; i<pa[cn].size(); i++) { fn = pa[cn][i].to; cnu = pa[cn][i].num; if(upa[cnu] == 1) continue; upa[cnu] = 1; ind[fn] --; patva[cnu] = nva[cn]; nva[fn] -= nva[cn]; if(ind[fn] == 1) { u[fn] = 1; qu.push(fn); cou ++; } } } cyn = n-cou; if(cyn % 2 == 0) { printf("0\n"); return 0; } su = 0; for(i=1; i<=n; i++) { if(u[i] == 0) { su += nva[i]; st = i; } } // if(su % 2 == 1) // { // printf("0\n"); // return 0; // } re(st,0); csu = 0; for(i=cyn-1; i>0; i-=2) { csu += nva[li[i]]; } patva[pnu[0]] = su/2 - csu; for(i=1; i<cyn; i++) { patva[pnu[i]] = nva[li[i]] - patva[pnu[i-1]]; } // if(patva[pnu[0]] + patva[pnu[cyn-1]] != nva[li[0]]) // { // printf("0\n"); // return 0; // } for(i=0; i<m; i++) { printf("%lld\n",patva[i] * 2); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 14436 KB | Output is correct |
2 | Correct | 8 ms | 14420 KB | Output is correct |
3 | Correct | 10 ms | 14468 KB | Output is correct |
4 | Correct | 104 ms | 24732 KB | Output is correct |
5 | Correct | 8 ms | 14496 KB | Output is correct |
6 | Correct | 8 ms | 14420 KB | Output is correct |
7 | Correct | 8 ms | 14420 KB | Output is correct |
8 | Correct | 8 ms | 14384 KB | Output is correct |
9 | Correct | 9 ms | 14420 KB | Output is correct |
10 | Correct | 8 ms | 14420 KB | Output is correct |
11 | Correct | 9 ms | 14532 KB | Output is correct |
12 | Correct | 8 ms | 14536 KB | Output is correct |
13 | Correct | 75 ms | 22636 KB | Output is correct |
14 | Correct | 89 ms | 24128 KB | Output is correct |
15 | Correct | 82 ms | 24760 KB | Output is correct |
16 | Correct | 66 ms | 23172 KB | Output is correct |
17 | Correct | 79 ms | 24652 KB | Output is correct |
18 | Correct | 98 ms | 24656 KB | Output is correct |
19 | Correct | 88 ms | 24348 KB | Output is correct |
20 | Correct | 7 ms | 14420 KB | Output is correct |
21 | Correct | 9 ms | 14420 KB | Output is correct |
22 | Correct | 83 ms | 24684 KB | Output is correct |
23 | Correct | 63 ms | 22632 KB | Output is correct |
24 | Correct | 100 ms | 24720 KB | Output is correct |
25 | Correct | 85 ms | 23032 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 14420 KB | Output is correct |
2 | Correct | 9 ms | 14548 KB | Output is correct |
3 | Correct | 64 ms | 23592 KB | Output is correct |
4 | Correct | 59 ms | 21528 KB | Output is correct |
5 | Correct | 51 ms | 21276 KB | Output is correct |
6 | Correct | 262 ms | 42696 KB | Output is correct |
7 | Correct | 8 ms | 14420 KB | Output is correct |
8 | Correct | 8 ms | 14400 KB | Output is correct |
9 | Correct | 8 ms | 14420 KB | Output is correct |
10 | Correct | 8 ms | 14420 KB | Output is correct |
11 | Correct | 8 ms | 14400 KB | Output is correct |
12 | Correct | 8 ms | 14420 KB | Output is correct |
13 | Correct | 8 ms | 14392 KB | Output is correct |
14 | Correct | 10 ms | 14396 KB | Output is correct |
15 | Correct | 9 ms | 14548 KB | Output is correct |
16 | Correct | 9 ms | 14548 KB | Output is correct |
17 | Correct | 9 ms | 14536 KB | Output is correct |
18 | Correct | 8 ms | 14404 KB | Output is correct |
19 | Correct | 8 ms | 14420 KB | Output is correct |
20 | Correct | 8 ms | 14420 KB | Output is correct |
21 | Correct | 8 ms | 14540 KB | Output is correct |
22 | Correct | 8 ms | 14540 KB | Output is correct |
23 | Correct | 71 ms | 26704 KB | Output is correct |
24 | Correct | 102 ms | 28584 KB | Output is correct |
25 | Correct | 82 ms | 23564 KB | Output is correct |
26 | Correct | 55 ms | 21528 KB | Output is correct |
27 | Correct | 52 ms | 21452 KB | Output is correct |
28 | Correct | 68 ms | 21772 KB | Output is correct |
29 | Correct | 207 ms | 37404 KB | Output is correct |
30 | Correct | 83 ms | 27652 KB | Output is correct |
31 | Correct | 86 ms | 31256 KB | Output is correct |
32 | Correct | 93 ms | 25816 KB | Output is correct |
33 | Correct | 75 ms | 24116 KB | Output is correct |
34 | Correct | 55 ms | 21524 KB | Output is correct |
35 | Correct | 54 ms | 21476 KB | Output is correct |
36 | Correct | 55 ms | 21580 KB | Output is correct |
37 | Correct | 251 ms | 42612 KB | Output is correct |
38 | Correct | 85 ms | 28168 KB | Output is correct |
39 | Correct | 82 ms | 25420 KB | Output is correct |
40 | Correct | 94 ms | 28440 KB | Output is correct |
41 | Correct | 67 ms | 23992 KB | Output is correct |
42 | Correct | 56 ms | 21580 KB | Output is correct |
43 | Correct | 60 ms | 21492 KB | Output is correct |
44 | Correct | 59 ms | 21316 KB | Output is correct |
45 | Correct | 183 ms | 39752 KB | Output is correct |
46 | Correct | 85 ms | 27400 KB | Output is correct |
47 | Correct | 87 ms | 28544 KB | Output is correct |
48 | Correct | 98 ms | 31024 KB | Output is correct |
49 | Correct | 71 ms | 23716 KB | Output is correct |
50 | Correct | 60 ms | 21708 KB | Output is correct |
51 | Correct | 59 ms | 21572 KB | Output is correct |
52 | Correct | 64 ms | 21504 KB | Output is correct |
53 | Correct | 195 ms | 39124 KB | Output is correct |
54 | Correct | 89 ms | 27212 KB | Output is correct |