Submission #1221808
Source Code Expand
#include <cstdio>
int edge[300000],next[300000],first[300000];
int r[300000];
bool c[300000];
int i,m,n,p,t,x,y,sum_edge;
bool b;
inline void addedge(int x,int y)
{
sum_edge++,edge[sum_edge]=y,next[sum_edge]=first[x],first[x]=sum_edge;
return;
}
int main()
{
scanf("%d%d",&n,&m);
for (i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
addedge(x,y),addedge(y,x);
}
c[1]=true;
p=1,b=true;
for (;b;)
{
b=false;
for (i=first[p];i!=0;i=next[i])
if (! c[edge[i]])
{
r[p]=edge[i],p=edge[i],b=true,c[p]=true;
break;
}
t++;
}
p=1,b=true;
for (;b;)
{
b=false;
for (i=first[p];i!=0;i=next[i])
if (! c[edge[i]])
{
r[edge[i]]=p,p=edge[i],b=true,c[p]=true;
break;
}
t++;
}
printf("%d\n",t-1);
for (i=p;i;i=r[i])
printf("%d ",i);
return 0;
}
Submission Info
Submission Time
2017-04-15 21:21:06+0900
Task
B - Hamiltonish Path
User
zhan8855
Language
C++14 (GCC 5.4.1)
Score
500
Code Size
837 Byte
Status
AC
Exec Time
30 ms
Memory
4096 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:17:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
^
./Main.cpp:20:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&x,&y);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
500 / 500
Status
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
2176 KB
sample_02.txt
AC
1 ms
2176 KB
sample_03.txt
AC
1 ms
2176 KB
subtask_1_01.txt
AC
17 ms
2944 KB
subtask_1_02.txt
AC
5 ms
2304 KB
subtask_1_03.txt
AC
15 ms
3200 KB
subtask_1_04.txt
AC
18 ms
3072 KB
subtask_1_05.txt
AC
18 ms
3200 KB
subtask_1_06.txt
AC
18 ms
3200 KB
subtask_1_07.txt
AC
18 ms
3072 KB
subtask_1_08.txt
AC
18 ms
3072 KB
subtask_1_09.txt
AC
30 ms
4096 KB
subtask_1_10.txt
AC
8 ms
2304 KB
subtask_1_11.txt
AC
9 ms
2432 KB
subtask_1_12.txt
AC
1 ms
2176 KB
subtask_1_13.txt
AC
1 ms
2176 KB