Submission #81500

# Submission time Handle Problem Language Result Execution time Memory
81500 2018-10-25T06:28:59 Z antimirage Pipes (BOI13_pipes) C++17
0 / 100
210 ms 25580 KB
#include <bits/stdc++.h>

#define mk make_pair
#define pb push_back
#define fr first
#define sc second

using namespace std;

const int N = 1e5 + 5;

long long n, m, ar[N], x, y, ans[N], sup[N];

vector < vector < pair <int, int> > > g;

void dfs (int v, int p = 0)
{
	for (auto to : g[v])
	{
		if (to.fr == p) continue;
		dfs(to.fr, v);
		ans[to.sc] = ar[to.fr] - sup[to.fr];
		sup[v] += ar[to.fr] - sup[to.fr];
	}
}

int main() 
{
	cin >> n >> m;
	g.resize(n + 1);
	
	assert(n - 1 == m);
	
	for (int i = 1; i <= n; i++)
		scanf("%I64d", &ar[i]);
		
	for (int i = 1; i <= m; i++)
	{
		scanf("%I64d%I64d", &x, &y);
		g[x].pb(mk(y,i) );
		g[y].pb(mk(x,i) );
	}
	dfs(1);
	if (ar[1] != sup[1])
	{
		puts("0");
		return 0;
	}
	for (int i = 1; i <= m; i++)
	{
		if(ans[i] * 2 > 1e9 || ans[i] * 2 < -1e9)
		{
			puts("0");
			return 0;
		}
	}
	for (int i = 1; i <= m; i++)
		printf("%I64d\n", ans[i] * 2);
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:35:24: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   scanf("%I64d", &ar[i]);
                  ~~~~~~^
pipes.cpp:39:29: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   scanf("%I64d%I64d", &x, &y);
                       ~~    ^
pipes.cpp:39:29: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
pipes.cpp:58:31: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   printf("%I64d\n", ans[i] * 2);
                     ~~~~~~~~~~^
pipes.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%I64d", &ar[i]);
   ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%I64d%I64d", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Incorrect 2 ms 616 KB Output isn't correct
3 Incorrect 3 ms 792 KB Output isn't correct
4 Incorrect 174 ms 10576 KB Output isn't correct
5 Incorrect 2 ms 10576 KB Output isn't correct
6 Incorrect 2 ms 10576 KB Output isn't correct
7 Incorrect 2 ms 10576 KB Output isn't correct
8 Incorrect 2 ms 10576 KB Output isn't correct
9 Incorrect 3 ms 10576 KB Output isn't correct
10 Incorrect 3 ms 10576 KB Output isn't correct
11 Incorrect 3 ms 10576 KB Output isn't correct
12 Incorrect 3 ms 10576 KB Output isn't correct
13 Incorrect 144 ms 10576 KB Output isn't correct
14 Incorrect 174 ms 13040 KB Output isn't correct
15 Incorrect 186 ms 15116 KB Output isn't correct
16 Incorrect 145 ms 15116 KB Output isn't correct
17 Incorrect 182 ms 18024 KB Output isn't correct
18 Incorrect 210 ms 19588 KB Output isn't correct
19 Incorrect 195 ms 24492 KB Output isn't correct
20 Incorrect 2 ms 24492 KB Output isn't correct
21 Incorrect 3 ms 24492 KB Output isn't correct
22 Incorrect 178 ms 24492 KB Output isn't correct
23 Incorrect 140 ms 24492 KB Output isn't correct
24 Incorrect 174 ms 25580 KB Output isn't correct
25 Incorrect 141 ms 25580 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 4 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 3 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 3 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 3 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 3 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 3 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 2 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 2 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 3 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 16 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 2 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 2 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 3 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 3 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 3 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Runtime error 3 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Runtime error 3 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Runtime error 6 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Runtime error 8 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
25 Runtime error 11 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Runtime error 9 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
27 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Runtime error 9 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
29 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
30 Runtime error 9 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Runtime error 9 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
33 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
35 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Runtime error 8 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
38 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
39 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Runtime error 8 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Runtime error 8 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Runtime error 10 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
43 Runtime error 8 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
44 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
45 Runtime error 5 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
46 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Runtime error 8 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
49 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
50 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
51 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
52 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
54 Runtime error 7 ms 25580 KB Execution killed with signal 11 (could be triggered by violating memory limits)