Submission #26391

# Submission time Handle Problem Language Result Execution time Memory
26391 2017-06-29T17:37:21 Z samir_droubi Pipes (BOI13_pipes) C++14
74.0741 / 100
676 ms 56308 KB
#include <bits/stdc++.h>
using namespace std;
int n,m;
const int mxn=(1e5)+5;
long long c[mxn];
queue<int>q;
set<pair<int,int> >gr[mxn];
int ans[mxn*5];
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);
	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[u].erase({v,in});
		if(gr[u].size()==1)q.push(u);
		ans[in]=2*c[v];
		c[u]-=c[v];
	}
	for(int i=1;i<=m;++i)printf("%d\n",ans[i]);
	return 0;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:13:19: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   scanf("%d",&c[i]);
                   ^
pipes.cpp:11: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:13:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&c[i]);
                    ^
pipes.cpp:17: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 0 ms 9448 KB Output is correct
2 Correct 0 ms 9448 KB Output is correct
3 Correct 3 ms 9580 KB Output is correct
4 Correct 169 ms 18952 KB Output is correct
5 Correct 0 ms 9448 KB Output is correct
6 Correct 0 ms 9448 KB Output is correct
7 Correct 3 ms 9448 KB Output is correct
8 Correct 3 ms 9448 KB Output is correct
9 Correct 0 ms 9580 KB Output is correct
10 Correct 0 ms 9580 KB Output is correct
11 Correct 0 ms 9580 KB Output is correct
12 Correct 0 ms 9580 KB Output is correct
13 Correct 136 ms 17104 KB Output is correct
14 Correct 139 ms 18424 KB Output is correct
15 Correct 179 ms 19084 KB Output is correct
16 Correct 139 ms 17632 KB Output is correct
17 Correct 163 ms 18952 KB Output is correct
18 Correct 179 ms 19084 KB Output is correct
19 Correct 136 ms 18820 KB Output is correct
20 Correct 3 ms 9448 KB Output is correct
21 Correct 3 ms 9580 KB Output is correct
22 Correct 183 ms 19084 KB Output is correct
23 Correct 133 ms 17104 KB Output is correct
24 Correct 176 ms 19084 KB Output is correct
25 Correct 123 ms 17368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 9448 KB Output isn't correct
2 Incorrect 0 ms 9580 KB Output isn't correct
3 Correct 89 ms 18292 KB Output is correct
4 Correct 83 ms 18820 KB Output is correct
5 Correct 89 ms 18556 KB Output is correct
6 Correct 676 ms 56308 KB Output is correct
7 Incorrect 0 ms 9448 KB Output isn't correct
8 Incorrect 0 ms 9448 KB Output isn't correct
9 Correct 0 ms 9448 KB Output is correct
10 Correct 3 ms 9448 KB Output is correct
11 Correct 0 ms 9448 KB Output is correct
12 Correct 0 ms 9448 KB Output is correct
13 Correct 0 ms 9448 KB Output is correct
14 Incorrect 0 ms 9448 KB Output isn't correct
15 Incorrect 3 ms 9580 KB Output isn't correct
16 Incorrect 3 ms 9580 KB Output isn't correct
17 Correct 0 ms 9580 KB Output is correct
18 Correct 0 ms 9580 KB Output is correct
19 Correct 0 ms 9580 KB Output is correct
20 Correct 0 ms 9580 KB Output is correct
21 Correct 0 ms 9712 KB Output is correct
22 Incorrect 0 ms 9580 KB Output isn't correct
23 Incorrect 69 ms 17104 KB Output isn't correct
24 Incorrect 99 ms 18820 KB Output isn't correct
25 Correct 103 ms 18292 KB Output is correct
26 Correct 93 ms 18820 KB Output is correct
27 Correct 93 ms 18820 KB Output is correct
28 Correct 106 ms 19348 KB Output is correct
29 Correct 449 ms 47068 KB Output is correct
30 Incorrect 83 ms 18688 KB Output isn't correct
31 Incorrect 89 ms 18820 KB Output isn't correct
32 Incorrect 96 ms 18820 KB Output isn't correct
33 Correct 93 ms 18820 KB Output is correct
34 Correct 89 ms 18820 KB Output is correct
35 Correct 119 ms 18820 KB Output is correct
36 Correct 96 ms 18952 KB Output is correct
37 Correct 636 ms 56308 KB Output is correct
38 Incorrect 89 ms 18820 KB Output isn't correct
39 Incorrect 86 ms 18820 KB Output isn't correct
40 Incorrect 106 ms 18820 KB Output isn't correct
41 Correct 89 ms 18820 KB Output is correct
42 Correct 96 ms 18820 KB Output is correct
43 Correct 96 ms 18820 KB Output is correct
44 Correct 123 ms 18556 KB Output is correct
45 Correct 543 ms 51028 KB Output is correct
46 Incorrect 86 ms 18820 KB Output isn't correct
47 Incorrect 96 ms 18820 KB Output isn't correct
48 Incorrect 83 ms 18820 KB Output isn't correct
49 Correct 96 ms 18292 KB Output is correct
50 Correct 86 ms 18820 KB Output is correct
51 Correct 89 ms 18820 KB Output is correct
52 Correct 99 ms 18688 KB Output is correct
53 Correct 523 ms 51820 KB Output is correct
54 Incorrect 113 ms 18688 KB Output isn't correct