Submission #25993

# Submission time Handle Problem Language Result Execution time Memory
25993 2017-06-25T15:54:17 Z H_H Senior Postmen (BOI14_postmen) C++14
55 / 100
500 ms 113784 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN=500005;
bool vis[MAXN];
bool vs[MAXN];
set<int>adj[MAXN];
int n,m;

int cyc=-1;

void dfs(int x)
{
	vis[x]=true;


	while(!adj[x].empty())
	{
		set<int>::iterator it=adj[x].end();
		--it;
		int y=*it;
		adj[x].erase(it);
		adj[y].erase(adj[y].find(x));
		if(vis[y])
		{
			printf("%d",x);
			cyc=y;
			break;
		}
		dfs(y);
		if(cyc!=-1)
		{
			printf(" %d",x);
			if(cyc==x)
			{
				printf("\n");
				cyc=-1;
			}
			else break;
		}
	}

	vis[x]=false;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		adj[x].insert(y);
		adj[y].insert(x);
	}
	
	for(int i=1;i<=n;i++)dfs(i);	
	return 0;
}

Compilation message

postmen.cpp: In function 'int main()':
postmen.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
postmen.cpp:51:8: 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 17 ms 23808 KB Output is correct
2 Correct 19 ms 23808 KB Output is correct
3 Correct 18 ms 23808 KB Output is correct
4 Correct 22 ms 24064 KB Output is correct
5 Correct 17 ms 23940 KB Output is correct
6 Correct 21 ms 24320 KB Output is correct
7 Correct 40 ms 25344 KB Output is correct
8 Correct 25 ms 24192 KB Output is correct
9 Correct 180 ms 33504 KB Output is correct
10 Correct 20 ms 24064 KB Output is correct
11 Correct 24 ms 24192 KB Output is correct
12 Correct 156 ms 33656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 18 ms 23808 KB Output is correct
4 Correct 20 ms 24064 KB Output is correct
5 Correct 19 ms 24000 KB Output is correct
6 Correct 23 ms 24192 KB Output is correct
7 Correct 33 ms 25216 KB Output is correct
8 Correct 19 ms 24192 KB Output is correct
9 Correct 187 ms 33504 KB Output is correct
10 Correct 19 ms 24192 KB Output is correct
11 Correct 18 ms 24064 KB Output is correct
12 Correct 173 ms 33656 KB Output is correct
13 Correct 123 ms 41724 KB Output is correct
14 Correct 140 ms 37752 KB Output is correct
15 Correct 142 ms 33760 KB Output is correct
16 Correct 129 ms 41688 KB Output is correct
17 Correct 141 ms 33784 KB Output is correct
18 Correct 134 ms 35832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23784 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 25 ms 23784 KB Output is correct
4 Correct 20 ms 24192 KB Output is correct
5 Correct 25 ms 23936 KB Output is correct
6 Correct 23 ms 24192 KB Output is correct
7 Correct 40 ms 25208 KB Output is correct
8 Correct 19 ms 24192 KB Output is correct
9 Correct 161 ms 33592 KB Output is correct
10 Correct 26 ms 24064 KB Output is correct
11 Correct 19 ms 24064 KB Output is correct
12 Correct 167 ms 33656 KB Output is correct
13 Correct 140 ms 41684 KB Output is correct
14 Correct 122 ms 37740 KB Output is correct
15 Correct 134 ms 33784 KB Output is correct
16 Correct 122 ms 41720 KB Output is correct
17 Correct 148 ms 33800 KB Output is correct
18 Correct 162 ms 35792 KB Output is correct
19 Execution timed out 658 ms 113784 KB Time limit exceeded
20 Halted 0 ms 0 KB -