Submission #106155

# Submission time Handle Problem Language Result Execution time Memory
106155 2019-04-16T21:39:57 Z luciocf Pipes (BOI13_pipes) C++14
0 / 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];
	}

	if (u != 1)
	{
		costEdge[edge[u]] = (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 Incorrect 4 ms 2688 KB Output isn't correct
2 Incorrect 4 ms 2688 KB Output isn't correct
3 Incorrect 7 ms 2944 KB Output isn't correct
4 Incorrect 99 ms 10152 KB Output isn't correct
5 Incorrect 4 ms 2688 KB Output isn't correct
6 Incorrect 4 ms 2688 KB Output isn't correct
7 Incorrect 5 ms 2688 KB Output isn't correct
8 Incorrect 5 ms 2688 KB Output isn't correct
9 Incorrect 5 ms 2688 KB Output isn't correct
10 Incorrect 8 ms 2816 KB Output isn't correct
11 Incorrect 5 ms 2816 KB Output isn't correct
12 Incorrect 6 ms 2816 KB Output isn't correct
13 Incorrect 77 ms 8500 KB Output isn't correct
14 Incorrect 107 ms 9660 KB Output isn't correct
15 Incorrect 122 ms 10076 KB Output isn't correct
16 Incorrect 96 ms 8952 KB Output isn't correct
17 Incorrect 106 ms 10108 KB Output isn't correct
18 Incorrect 90 ms 9976 KB Output isn't correct
19 Incorrect 112 ms 12536 KB Output isn't correct
20 Incorrect 4 ms 2816 KB Output isn't correct
21 Incorrect 5 ms 2688 KB Output isn't correct
22 Incorrect 105 ms 10032 KB Output isn't correct
23 Incorrect 115 ms 8440 KB Output isn't correct
24 Incorrect 113 ms 10000 KB Output isn't correct
25 Incorrect 94 ms 8720 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Runtime error 139 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 158 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 740 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 643 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 204 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 402 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 125 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 151 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 131 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 116 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 140 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 123 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 119 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 133 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 129 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 140 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 136 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Runtime error 123 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Runtime error 117 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
21 Runtime error 119 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
22 Runtime error 157 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
23 Runtime error 631 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
24 Runtime error 769 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
25 Runtime error 773 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
26 Runtime error 617 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Runtime error 456 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
28 Runtime error 177 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
29 Runtime error 308 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
30 Execution timed out 1016 ms 132096 KB Time limit exceeded
31 Runtime error 597 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
32 Execution timed out 1084 ms 132096 KB Time limit exceeded
33 Runtime error 605 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
34 Runtime error 303 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
35 Runtime error 679 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Runtime error 186 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
37 Runtime error 393 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
38 Runtime error 637 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Execution timed out 1056 ms 116032 KB Time limit exceeded
40 Runtime error 668 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
41 Runtime error 529 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Runtime error 469 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
43 Runtime error 549 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
44 Runtime error 203 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
45 Runtime error 351 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
46 Execution timed out 1083 ms 122460 KB Time limit exceeded
47 Runtime error 585 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
48 Runtime error 606 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
49 Execution timed out 1073 ms 107828 KB Time limit exceeded
50 Runtime error 667 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
51 Runtime error 825 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
52 Runtime error 321 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
53 Runtime error 385 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
54 Runtime error 722 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)