Submission #26446

# Submission time Handle Problem Language Result Execution time Memory
26446 2017-06-30T19:10:53 Z samir_droubi Pipes (BOI13_pipes) C++14
74.0741 / 100
629 ms 55920 KB
#include <bits/stdc++.h>
using namespace std;
int n,m;
const int mxn=(1e5)+5;
set<pair<int,int> >gr[mxn];
queue<int>q;
int c[mxn];
int ans[mxn*5];

void run()
{
	while(!q.empty())
	{
		int v=q.front();
		q.pop();
		if(gr[v].empty())continue;

		int u=gr[v].begin()->first;
		int in=gr[v].begin()->second;

		gr[v].clear();
		gr[u].erase({v,in});

		if(gr[u].size()==1)q.push(u);

		ans[in]=2*c[v];
		c[u]-=c[v];
	}
}
int sm;
int num;
int cnt;
void dfs(int v,int pa)
{
	++num;
	if(num%2)sm+=c[v];
	else sm-=c[v];

	cout<<v<<" "<<sm<<endl;
	set<pair<int,int > >::iterator it=gr[v].begin();
	for(it;it!=gr[v].end();++it)
	{
		int u=it->first;
		int in=it->second;
		if(u==pa)continue;
		if(cnt==num)
		{
			ans[in]=sm;
			c[u]-=(sm/2);
			c[v]-=(sm/2);
			gr[u].erase({v,in});
			gr[v].erase(it);	
			q.push(v);
			return;
		}
		dfs(u,v);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d",&c[i]);
	for(int i=1;i<=m;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		gr[x].insert({y,i});
		gr[y].insert({x,i});
	}
	if(m>n)
	{
		puts("0");
		return 0;
	}

	for(int i=1;i<=n;++i)
	{
		if(gr[i].size()==1)
			q.push(i);
	}
	run();
	if(n==m)
	{
		for(int i=1;i<=n;++i)
		{
			if(gr[i].empty())continue;
			++cnt;
		}
		if(cnt%2==0)
		{
			puts("0");
			return 0;
		}
		for(int i=1;i<=n;++i)
		{
			if(gr[i].empty())continue;
			dfs(i,i);
			break;
		}
		run();
	}
	for(int i=1;i<=m;++i)
		printf("%d\n",ans[i]);
	return 0;
}

Compilation message

pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:41:8: warning: statement has no effect [-Wunused-value]
  for(it;it!=gr[v].end();++it)
        ^
pipes.cpp: In function 'int main()':
pipes.cpp:61:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
                     ^
pipes.cpp:62:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;++i)scanf("%d",&c[i]);
                                        ^
pipes.cpp:66:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&x,&y);
                      ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9060 KB Output is correct
2 Correct 3 ms 9060 KB Output is correct
3 Correct 0 ms 9192 KB Output is correct
4 Correct 153 ms 18564 KB Output is correct
5 Correct 3 ms 9060 KB Output is correct
6 Correct 0 ms 9060 KB Output is correct
7 Correct 0 ms 9060 KB Output is correct
8 Correct 3 ms 9060 KB Output is correct
9 Correct 0 ms 9192 KB Output is correct
10 Correct 0 ms 9192 KB Output is correct
11 Correct 0 ms 9192 KB Output is correct
12 Correct 0 ms 9192 KB Output is correct
13 Correct 113 ms 16716 KB Output is correct
14 Correct 153 ms 18036 KB Output is correct
15 Correct 159 ms 18696 KB Output is correct
16 Correct 126 ms 17244 KB Output is correct
17 Correct 156 ms 18564 KB Output is correct
18 Correct 143 ms 18696 KB Output is correct
19 Correct 126 ms 18432 KB Output is correct
20 Correct 3 ms 9060 KB Output is correct
21 Correct 3 ms 9192 KB Output is correct
22 Correct 139 ms 18696 KB Output is correct
23 Correct 119 ms 16716 KB Output is correct
24 Correct 186 ms 18696 KB Output is correct
25 Correct 139 ms 16980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 9060 KB Output isn't correct
2 Incorrect 3 ms 9192 KB Output isn't correct
3 Correct 119 ms 18036 KB Output is correct
4 Correct 89 ms 18432 KB Output is correct
5 Correct 96 ms 18168 KB Output is correct
6 Correct 616 ms 55920 KB Output is correct
7 Incorrect 0 ms 9060 KB Output isn't correct
8 Incorrect 0 ms 9060 KB Output isn't correct
9 Correct 0 ms 9060 KB Output is correct
10 Correct 0 ms 9060 KB Output is correct
11 Correct 3 ms 9060 KB Output is correct
12 Correct 0 ms 9060 KB Output is correct
13 Correct 0 ms 9060 KB Output is correct
14 Incorrect 0 ms 9060 KB Output isn't correct
15 Incorrect 3 ms 9192 KB Output isn't correct
16 Incorrect 3 ms 9192 KB Output isn't correct
17 Correct 3 ms 9192 KB Output is correct
18 Correct 0 ms 9192 KB Output is correct
19 Correct 0 ms 9192 KB Output is correct
20 Correct 0 ms 9192 KB Output is correct
21 Correct 3 ms 9324 KB Output is correct
22 Incorrect 0 ms 9192 KB Output isn't correct
23 Runtime error 216 ms 19840 KB Execution timed out (wall clock limit exceeded)
24 Runtime error 196 ms 21276 KB Execution timed out (wall clock limit exceeded)
25 Correct 129 ms 18036 KB Output is correct
26 Correct 96 ms 18432 KB Output is correct
27 Correct 89 ms 18432 KB Output is correct
28 Correct 103 ms 18960 KB Output is correct
29 Correct 496 ms 46680 KB Output is correct
30 Incorrect 229 ms 20980 KB Output isn't correct
31 Incorrect 256 ms 23756 KB Output isn't correct
32 Incorrect 206 ms 19488 KB Output isn't correct
33 Correct 113 ms 18564 KB Output is correct
34 Correct 103 ms 18432 KB Output is correct
35 Correct 86 ms 18432 KB Output is correct
36 Correct 126 ms 18564 KB Output is correct
37 Correct 626 ms 55920 KB Output is correct
38 Incorrect 213 ms 21204 KB Output isn't correct
39 Incorrect 196 ms 19092 KB Output isn't correct
40 Incorrect 209 ms 21416 KB Output isn't correct
41 Correct 123 ms 18432 KB Output is correct
42 Correct 113 ms 18432 KB Output is correct
43 Correct 99 ms 18432 KB Output is correct
44 Correct 106 ms 18168 KB Output is correct
45 Correct 629 ms 50640 KB Output is correct
46 Incorrect 269 ms 20852 KB Output isn't correct
47 Incorrect 269 ms 21512 KB Output isn't correct
48 Incorrect 279 ms 23552 KB Output isn't correct
49 Correct 129 ms 18036 KB Output is correct
50 Correct 106 ms 18432 KB Output is correct
51 Correct 106 ms 18432 KB Output is correct
52 Correct 83 ms 18300 KB Output is correct
53 Correct 593 ms 51432 KB Output is correct
54 Incorrect 239 ms 20608 KB Output isn't correct