Submission #111612

# Submission time Handle Problem Language Result Execution time Memory
111612 2019-05-15T17:21:44 Z wilwxk Pipes (BOI13_pipes) C++11
30 / 100
1000 ms 132096 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5+5;
vector<int> g[MAXN], lista[MAXN];
int v[MAXN], tenho[MAXN], resp[MAXN];
int n, m;

void dfs(int cur, int p) {
	tenho[cur]=0;
	for(int i=0; i<g[cur].size(); i++) {
		int viz=g[cur][i]; int ind=lista[cur][i];
		if(viz==p) continue;
		dfs(viz, cur);
		resp[ind]=v[viz]-tenho[viz];
		tenho[cur]+=resp[ind];
	}
}

int main() {
	scanf("%d %d", &n, &m);
	for(int i=1; i<=n; i++) scanf("%d", &v[i]);
	for(int i=1; i<=m; i++) {
		int a, b; scanf("%d %d", &a, &b);
		g[a].push_back(b); g[b].push_back(a);
		lista[a].push_back(i); lista[b].push_back(i);
	}

	dfs(1, 1);

	if(tenho[1]!=v[1]) {
		printf("0\n");
	}
	else {
		for(int i=1; i<=m; i++) {
			printf("%d\n", resp[i]*2);
		}
	}


}

Compilation message

pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:11:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<g[cur].size(); i++) {
               ~^~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:22:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=n; i++) scanf("%d", &v[i]);
                          ~~~~~^~~~~~~~~~~~~
pipes.cpp:24:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d %d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5248 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 123 ms 14684 KB Output is correct
5 Correct 5 ms 5120 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 5 ms 4992 KB Output is correct
8 Correct 5 ms 4992 KB Output is correct
9 Correct 6 ms 5120 KB Output is correct
10 Correct 6 ms 5248 KB Output is correct
11 Correct 6 ms 5120 KB Output is correct
12 Correct 6 ms 5248 KB Output is correct
13 Correct 99 ms 12684 KB Output is correct
14 Correct 103 ms 14076 KB Output is correct
15 Correct 133 ms 14712 KB Output is correct
16 Correct 95 ms 13180 KB Output is correct
17 Correct 161 ms 14744 KB Output is correct
18 Correct 202 ms 14840 KB Output is correct
19 Correct 157 ms 18296 KB Output is correct
20 Correct 6 ms 4992 KB Output is correct
21 Correct 9 ms 5120 KB Output is correct
22 Correct 143 ms 14712 KB Output is correct
23 Correct 114 ms 12828 KB Output is correct
24 Correct 145 ms 14712 KB Output is correct
25 Correct 97 ms 13052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 123 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 120 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 642 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 658 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 229 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 511 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 122 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 165 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 117 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 115 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 119 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 120 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 112 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 118 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 122 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 175 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 148 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 133 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Runtime error 154 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Runtime error 109 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
21 Runtime error 118 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
22 Runtime error 120 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
23 Runtime error 598 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
24 Runtime error 790 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
25 Runtime error 717 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
26 Runtime error 684 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Runtime error 579 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
28 Runtime error 204 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
29 Runtime error 466 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
30 Runtime error 980 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
31 Runtime error 567 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
32 Execution timed out 1048 ms 132096 KB Time limit exceeded
33 Runtime error 580 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
34 Runtime error 362 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
35 Runtime error 619 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Runtime error 232 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
37 Runtime error 605 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
38 Runtime error 789 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Execution timed out 1069 ms 84088 KB Time limit exceeded
40 Runtime error 686 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
41 Runtime error 594 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Runtime error 567 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
43 Runtime error 569 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
44 Runtime error 239 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
45 Runtime error 473 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
46 Execution timed out 1076 ms 126588 KB Time limit exceeded
47 Runtime error 527 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
48 Runtime error 638 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
49 Execution timed out 1083 ms 105820 KB Time limit exceeded
50 Runtime error 673 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
51 Runtime error 657 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
52 Runtime error 353 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
53 Runtime error 479 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
54 Runtime error 651 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)