Submission #114765

#TimeUsernameProblemLanguageResultExecution timeMemory
114765luciocfPipes (BOI13_pipes)C++14
30 / 100
1082 ms131072 KiB
#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);
 
	for (int i = 1; i <= m; i++)
		printf("%d\n", costEdge[i]);
}

Compilation message (stderr)

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