Submission #81502

#TimeUsernameProblemLanguageResultExecution timeMemory
81502antimiragePipes (BOI13_pipes)C++17
0 / 100
203 ms24488 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...