Submission #81502

# Submission time Handle Problem Language Result Execution time Memory
81502 2018-10-25T06:30:51 Z antimirage Pipes (BOI13_pipes) C++17
0 / 100
203 ms 24488 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);
	for (int i = 1; i <= m; i++)
		assert(ans[i] * 2 <= 1e9 && ans[i] * 2 >= -1e9);
		
	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:48: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 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 3 ms 644 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 4 ms 912 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 181 ms 17728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 4 ms 17728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 3 ms 17728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 3 ms 17728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 3 ms 17728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 4 ms 17728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 4 ms 17728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 4 ms 17728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 4 ms 17728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 134 ms 17728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 163 ms 17728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 175 ms 17776 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 151 ms 17776 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 185 ms 17776 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 187 ms 17776 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 203 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 5 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Runtime error 4 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Runtime error 192 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Runtime error 149 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Runtime error 182 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
25 Runtime error 152 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 2 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 6 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 8 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 4 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 2 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 2 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 3 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 2 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 2 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 2 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 2 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 2 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 2 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 2 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 2 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 3 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 3 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Runtime error 2 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Runtime error 2 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Runtime error 6 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
25 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
27 Runtime error 8 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Runtime error 8 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
29 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
30 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
33 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
35 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Runtime error 8 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
38 Runtime error 8 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
39 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Runtime error 8 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Runtime error 8 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
43 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
44 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
45 Runtime error 5 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
46 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
49 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
50 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
51 Runtime error 8 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
52 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Runtime error 6 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
54 Runtime error 7 ms 24488 KB Execution killed with signal 11 (could be triggered by violating memory limits)