Submission #1304463


Source Code Expand

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<algorithm>
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define For(i,x,y) for(int i=((int)x);i<=((int)y);i++)
#define Dep(i,y,x) for(int i=((int)y);i>=((int)x);i--)
#define Rep(i,x) for (int y,i=head[x];i;i=E[i].nxt) if (!vis[y=E[i].to])
using namespace std;
 
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;
 
int rd() {
	char c=getchar_unlocked(); int t=0,f=1;
	while (!isdigit(c)) f=(c=='-')?-1:1,c=getchar_unlocked();
	while (isdigit(c)) t=t*10+c-48,c=getchar_unlocked(); return t*f;
}
void wt(int x) {
	if (x<0) putchar_unlocked('-'),wt(-x);
	else { if (x>9) wt(x/10); putchar_unlocked(x%10+48); }
}
 
const int N=300035;
 
int n,m,head[N],cnt;
struct Edge { int to,nxt; }E[N<<1];
void Link(int u,int v) {
	E[++cnt]=(Edge){v,head[u]}; head[u]=cnt;
	E[++cnt]=(Edge){u,head[v]}; head[v]=cnt;
}
 
int stk[N],top,vis[N];
 
bool dfs1(int x) {
	vis[x]=1,stk[++top]=x;
	Rep (i,x) if (dfs1(y)) return 1;
	return 1;
}
 
bool dfs2(int x) {
	vis[x]=1,stk[++top]=x;
	Rep (i,x) if (dfs2(y)) return 1;
	return 1;
}
 
int main() {
	n=rd(),m=rd();
	For (i,1,m) Link(rd(),rd());
	dfs1(1);
	reverse(stk+1,stk+top+1); top--;
	dfs2(1);
	
	printf("%d\n",top);
	while (top) printf("%d ",stk[top--]);
	
	return 0;
}

Submission Info

Submission Time
Task B - Hamiltonish Path
User eukaryo
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1503 Byte
Status AC
Exec Time 17 ms
Memory 6912 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 19
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 4224 KB
sample_02.txt AC 1 ms 4224 KB
sample_03.txt AC 1 ms 4224 KB
subtask_1_01.txt AC 4 ms 4224 KB
subtask_1_02.txt AC 2 ms 4352 KB
subtask_1_03.txt AC 4 ms 4608 KB
subtask_1_04.txt AC 5 ms 4480 KB
subtask_1_05.txt AC 5 ms 4480 KB
subtask_1_06.txt AC 5 ms 4480 KB
subtask_1_07.txt AC 5 ms 4224 KB
subtask_1_08.txt AC 5 ms 4224 KB
subtask_1_09.txt AC 17 ms 6912 KB
subtask_1_10.txt AC 3 ms 4224 KB
subtask_1_11.txt AC 3 ms 4224 KB
subtask_1_12.txt AC 1 ms 4224 KB
subtask_1_13.txt AC 1 ms 4224 KB