#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
const int maxn=5e3+3;
struct Edge{
int x,y;
bool operator <(const Edge&a)const{
if(x!=a.x)return x<a.x;
return y<a.y;
}
}c[maxn<<1];
struct Road{
int to;
int last;
}a[maxn<<1];
int n;
int m;
int T;
int mm;
int s,t;
int cnt;
int tot;
int haha;
bool flag;
int ans[maxn];
int vis[maxn];
int head[maxn];
int temp[maxn];
bool HA();
void I(int&);
void HAHA(int);
void HA(int,int);
int main(){
I(n),I(m);
for(int i=1,x,y;i<=m;++i)
I(c[mm].x),I(c[mm].y),++mm,
c[mm].x=c[mm-1].y,c[mm].y=c[mm-1].x,++mm;
std::sort(c,c+mm);
for(int i=mm-1;~i;--i)
HA(c[i].x,c[i].y);
if(m==n-1){
T=1,HAHA(1);
for(int i=1;i<n;++i)
printf("%d ",temp[i]);
printf("%d\n",temp[n]);
return 0;
}
for(int i=1;i<=tot;++i){
s=c[i].x,t=c[i].y;
cnt=0,++T,haha=0,HAHA(1);
if(cnt==n && (!flag || HA()))
memcpy(ans,temp,sizeof(ans)),flag=true;
}
for(int i=1;i<n;++i)
printf("%d ",ans[i]);
printf("%d\n",ans[n]);
return 0;
}
inline void HA(int x,int y){
a[++tot].to=y;
a[tot].last=head[x];
head[x]=tot;
}
inline void I(int&x){
register char ch;
while(ch=getchar(),ch<'/');x=ch-'0';
while(ch=getchar(),ch>'/')x=((x+(x<<2))<<1)+ch-'0';
}
inline bool HA(){
for(int i=1;i<=n;++i)
if(ans[i]!=temp[i])
return temp[i]<ans[i];
return false;
}
#define y a[i].to
inline void HAHA(int x){
if(haha==-1)return;
vis[x]=T,temp[++cnt]=x;
if(flag && !haha && temp[cnt]>ans[cnt])
return haha=-1,void();
if(flag && temp[cnt]<ans[cnt])haha=1;
for(int i=head[x];i;i=a[i].last){
if(vis[y]==T)continue;
if(x==s && y==t)continue;
if(x==t && y==s)continue;
HAHA(y);
}
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 39.62 us | 60 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 44.48 us | 60 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 45.84 us | 60 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 60.37 us | 64 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 60.96 us | 64 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 297.09 us | 136 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 296.98 us | 140 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 295.94 us | 144 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 304.62 us | 128 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 301.22 us | 124 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 1.498 ms | 380 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 1.507 ms | 420 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 1.498 ms | 432 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 1.497 ms | 380 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 1.491 ms | 460 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 45.3 us | 80 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 44.17 us | 80 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 96.86 us | 84 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 114.61 us | 84 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 627.4 us | 168 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 407.65 us | 168 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 8.573 ms | 168 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 5.722 ms | 456 KB | Accepted | Score: 4 | 显示更多 |
Testcase #24 | 3.972 ms | 444 KB | Accepted | Score: 4 | 显示更多 |
Testcase #25 | 4.593 ms | 432 KB | Accepted | Score: 4 | 显示更多 |