Submission #25995

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

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

int cyc=-1;

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

	while(it[x]<adj[x].size())
	{
		int i=it[x];
		int y=adj[x][i].first;
		int in=adj[x][i].second;
		if(vs[in])
		{
			it[x]++;
			continue;
		}
		it[x]++;
		vs[in]=true;
		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].push_back({y,i});
		adj[y].push_back({x,i});
	}
	
	for(int i=1;i<=n;i++)dfs(i);	
	return 0;
}

Compilation message

postmen.cpp: In function 'void dfs(int)':
postmen.cpp:17:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(it[x]<adj[x].size())
        ~~~~~^~~~~~~~~~~~~~
postmen.cpp: In function 'int main()':
postmen.cpp:52: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:56: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 11 ms 12160 KB Output is correct
2 Correct 11 ms 12032 KB Output is correct
3 Correct 11 ms 12160 KB Output is correct
4 Correct 14 ms 12160 KB Output is correct
5 Correct 15 ms 12160 KB Output is correct
6 Correct 16 ms 12288 KB Output is correct
7 Correct 25 ms 12672 KB Output is correct
8 Correct 12 ms 12288 KB Output is correct
9 Correct 63 ms 14688 KB Output is correct
10 Correct 17 ms 12160 KB Output is correct
11 Correct 13 ms 12160 KB Output is correct
12 Correct 58 ms 14880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12160 KB Output is correct
2 Correct 12 ms 12032 KB Output is correct
3 Correct 12 ms 12136 KB Output is correct
4 Correct 13 ms 12160 KB Output is correct
5 Correct 12 ms 12160 KB Output is correct
6 Correct 13 ms 12160 KB Output is correct
7 Correct 19 ms 12544 KB Output is correct
8 Correct 13 ms 12288 KB Output is correct
9 Correct 53 ms 14456 KB Output is correct
10 Correct 13 ms 12160 KB Output is correct
11 Correct 13 ms 12288 KB Output is correct
12 Correct 59 ms 14920 KB Output is correct
13 Correct 91 ms 21112 KB Output is correct
14 Correct 88 ms 15996 KB Output is correct
15 Correct 77 ms 15640 KB Output is correct
16 Correct 93 ms 21076 KB Output is correct
17 Correct 95 ms 15864 KB Output is correct
18 Correct 94 ms 17200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12160 KB Output is correct
2 Correct 11 ms 12032 KB Output is correct
3 Correct 14 ms 12032 KB Output is correct
4 Correct 15 ms 12160 KB Output is correct
5 Correct 12 ms 12160 KB Output is correct
6 Correct 13 ms 12288 KB Output is correct
7 Correct 26 ms 12544 KB Output is correct
8 Correct 13 ms 12272 KB Output is correct
9 Correct 73 ms 14516 KB Output is correct
10 Correct 15 ms 12136 KB Output is correct
11 Correct 14 ms 12160 KB Output is correct
12 Correct 54 ms 14840 KB Output is correct
13 Correct 117 ms 21116 KB Output is correct
14 Correct 140 ms 15992 KB Output is correct
15 Correct 94 ms 15592 KB Output is correct
16 Correct 108 ms 21044 KB Output is correct
17 Correct 111 ms 15864 KB Output is correct
18 Correct 89 ms 17180 KB Output is correct
19 Execution timed out 553 ms 57592 KB Time limit exceeded
20 Halted 0 ms 0 KB -