Submission #158260

# Submission time Handle Problem Language Result Execution time Memory
158260 2019-10-15T21:04:49 Z MohamedAhmed04 Pipes (BOI13_pipes) C++14
74.0741 / 100
176 ms 22252 KB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 1e5 + 10 ;

vector< vector<int> >adj(MAX) ;
int n , m ;
int dep[MAX], P[MAX] , arr[MAX] ;

vector< pair<int , int> >vp ;
map< pair<int , int> , int>mp ;

void dfs1(int node , int par , int lvl)
{
	P[node] = par ;
	dep[node] = lvl ;
	for(auto &child : adj[node])
	{
		if(child == par)
			continue ;
		dfs1(child , node , lvl+1) ;
	}
	return ;
}

void solve1()
{
	dfs1(1 , -1 , 0) ;
	vector< vector<int> >v(n+1) ;
	for(int i = 1 ; i <= n ; ++i)
		v[dep[i]].push_back(i) ;
	for(int i = n ; i >= 1 ; --i)
	{
		for(auto &node : v[i])
		{
			int a = min(node , P[node]) , b = max(node , P[node]) ;
			mp[{a , b}] = arr[node] ;
			arr[P[node]] -= arr[node] ;
		}
	}
	for(auto &i : vp)
	{
		int a = min(i.first , i.second) ;
		int b = max(i.first , i.second) ;
		cout<<mp[{a , b}] * 2<<"\n" ;
	}
	return ;
}

void solve2()
{
	cout<<0<<"\n" ;
	return ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	if(m > n)
		return cout<<0<<"\n" , 0 ;
	for(int i = 1 ; i <= n ; ++i)
		cin>>arr[i] ;
	for(int i = 0 ; i < m ; ++i)
	{
		int x , y ;
		cin>>x>>y ;
		adj[x].push_back(y) ;
		adj[y].push_back(x) ;
		vp.push_back({x , y}) ;
	}
	if(m == n-1)
		solve1() ;
	else
		solve2() ;
	return 0 ;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 5 ms 2808 KB Output is correct
4 Correct 125 ms 18928 KB Output is correct
5 Correct 4 ms 2748 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Correct 4 ms 2780 KB Output is correct
8 Correct 4 ms 2780 KB Output is correct
9 Correct 5 ms 2808 KB Output is correct
10 Correct 5 ms 2936 KB Output is correct
11 Correct 5 ms 2936 KB Output is correct
12 Correct 5 ms 2936 KB Output is correct
13 Correct 107 ms 15724 KB Output is correct
14 Correct 131 ms 18072 KB Output is correct
15 Correct 138 ms 19016 KB Output is correct
16 Correct 112 ms 16552 KB Output is correct
17 Correct 153 ms 18944 KB Output is correct
18 Correct 140 ms 19004 KB Output is correct
19 Correct 176 ms 22252 KB Output is correct
20 Correct 4 ms 2556 KB Output is correct
21 Correct 5 ms 2936 KB Output is correct
22 Correct 143 ms 19052 KB Output is correct
23 Correct 110 ms 15596 KB Output is correct
24 Correct 132 ms 19024 KB Output is correct
25 Correct 119 ms 16336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2684 KB Output isn't correct
2 Incorrect 5 ms 2792 KB Output isn't correct
3 Correct 55 ms 8312 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Incorrect 4 ms 2680 KB Output isn't correct
8 Incorrect 4 ms 2680 KB Output isn't correct
9 Correct 4 ms 2680 KB Output is correct
10 Correct 4 ms 2680 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 4 ms 2680 KB Output is correct
13 Correct 4 ms 2680 KB Output is correct
14 Incorrect 4 ms 2680 KB Output isn't correct
15 Incorrect 4 ms 2808 KB Output isn't correct
16 Incorrect 5 ms 2808 KB Output isn't correct
17 Correct 4 ms 2808 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 4 ms 2680 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 5 ms 2680 KB Output is correct
22 Incorrect 4 ms 2680 KB Output isn't correct
23 Incorrect 54 ms 7664 KB Output isn't correct
24 Incorrect 64 ms 8684 KB Output isn't correct
25 Correct 63 ms 8428 KB Output is correct
26 Correct 4 ms 2680 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Incorrect 59 ms 8488 KB Output isn't correct
31 Incorrect 57 ms 8512 KB Output isn't correct
32 Incorrect 60 ms 8684 KB Output isn't correct
33 Correct 59 ms 8672 KB Output is correct
34 Correct 4 ms 2680 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 4 ms 2680 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Incorrect 63 ms 8528 KB Output isn't correct
39 Incorrect 65 ms 8556 KB Output isn't correct
40 Incorrect 61 ms 8556 KB Output isn't correct
41 Correct 64 ms 8668 KB Output is correct
42 Correct 4 ms 2680 KB Output is correct
43 Correct 4 ms 2680 KB Output is correct
44 Correct 5 ms 2680 KB Output is correct
45 Correct 4 ms 2680 KB Output is correct
46 Incorrect 59 ms 8528 KB Output isn't correct
47 Incorrect 65 ms 8656 KB Output isn't correct
48 Incorrect 64 ms 8696 KB Output isn't correct
49 Correct 56 ms 8428 KB Output is correct
50 Correct 5 ms 2680 KB Output is correct
51 Correct 5 ms 2680 KB Output is correct
52 Correct 4 ms 2680 KB Output is correct
53 Correct 5 ms 2680 KB Output is correct
54 Incorrect 58 ms 8556 KB Output isn't correct