Submission #106156

# Submission time Handle Problem Language Result Execution time Memory
106156 2019-04-16T21:44:37 Z luciocf Pipes (BOI13_pipes) C++14
30 / 100
1000 ms 132096 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5+10;
const int maxm = 5e5+10;

typedef pair<int, int> pii;

int a[maxn], cur[maxn];

int edge[maxn], costEdge[maxm];

vector<pii> grafo[maxn];

void dfs(int u, int p)
{
	for (auto pp: grafo[u])
	{
		int v = pp.first, e = pp.second;
		if (v == p) continue;

		edge[v] = e;

		dfs(v, u);

		cur[u] += costEdge[e]/2;
	}

	if (u != 1)
	{
		costEdge[edge[u]] = 2*(a[u]-cur[u]);
		cur[u] = a[u];
	}
}

int main(void)
{
	int n, m;
	scanf("%d %d", &n, &m);

	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	for (int i = 1; i <= m; i++)
	{
		int u, v;
		scanf("%d %d", &u, &v);

		grafo[u].push_back({v, i});
		grafo[v].push_back({u, i});
	}

	dfs(1, 0);

	if (cur[1] != a[1]) printf("0\n");
	else
	{
		for (int i = 1; i <= m; i++)
			printf("%d\n", costEdge[i]);
	}
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:40: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:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
pipes.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 5 ms 2688 KB Output is correct
4 Correct 77 ms 8312 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 3 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 5 ms 2816 KB Output is correct
10 Correct 5 ms 2688 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 4 ms 2816 KB Output is correct
13 Correct 61 ms 7260 KB Output is correct
14 Correct 82 ms 8148 KB Output is correct
15 Correct 85 ms 8440 KB Output is correct
16 Correct 65 ms 7544 KB Output is correct
17 Correct 85 ms 8488 KB Output is correct
18 Correct 80 ms 8440 KB Output is correct
19 Correct 106 ms 10972 KB Output is correct
20 Correct 5 ms 2688 KB Output is correct
21 Correct 5 ms 2816 KB Output is correct
22 Correct 94 ms 8392 KB Output is correct
23 Correct 71 ms 7236 KB Output is correct
24 Correct 90 ms 8516 KB Output is correct
25 Correct 73 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 127 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 129 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 836 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 706 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 207 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 418 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 116 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 149 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 135 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 117 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 109 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 112 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 115 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 114 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 121 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 138 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 133 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 159 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Runtime error 129 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Runtime error 121 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
21 Runtime error 108 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
22 Runtime error 135 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
23 Runtime error 538 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
24 Runtime error 786 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
25 Runtime error 863 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
26 Runtime error 663 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Runtime error 431 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
28 Runtime error 178 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
29 Runtime error 327 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
30 Execution timed out 1082 ms 132096 KB Time limit exceeded
31 Runtime error 598 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
32 Execution timed out 1083 ms 111096 KB Time limit exceeded
33 Runtime error 608 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
34 Runtime error 332 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
35 Runtime error 643 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Runtime error 203 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
37 Runtime error 413 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
38 Runtime error 803 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Execution timed out 1067 ms 62572 KB Time limit exceeded
40 Runtime error 829 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
41 Runtime error 670 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Runtime error 605 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
43 Runtime error 640 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
44 Runtime error 223 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
45 Runtime error 313 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
46 Execution timed out 1080 ms 110384 KB Time limit exceeded
47 Runtime error 575 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
48 Runtime error 662 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
49 Execution timed out 1074 ms 119020 KB Time limit exceeded
50 Runtime error 484 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
51 Runtime error 618 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
52 Runtime error 318 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
53 Runtime error 363 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
54 Runtime error 704 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)