#include<cstdio>
#include<cstring>
#define IO(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
const int str=1<<22;
const char* endl="\n";
struct Reader {
char buf[str],*s,*t;
Reader():s(buf),t(buf) {};
inline char gt() {
return s==t&&((t=(s=buf)+fread(buf,1,str,stdin))==s)?EOF:(*s++);
}
template<typename T>Reader&operator>>(T&x) {
register char c=0,d;
while(c<'0'||c>'9')d=c,c=gt();
x=0;
while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=gt();
if(d=='-')x=-x;
return *this;
}
} cin;
struct Writer {
char buf[str],*s,*t;
Writer():s(buf),t(buf+str) {}
~Writer() {
fwrite(buf,1,s-buf,stdout);
}
inline void pt(char c) {
(s==t)?(fwrite(s=buf,1,str,stdout),*s++=c):(*s++=c);
}
template<typename T>Writer&operator<<(T x) {
if(!x)return pt('0'),*this;
if(x<0)pt('-'),x=-x;
register char a[30],t=0;
while(x)a[t++]=x%10,x/=10;
while(t--)pt(a[t]+'0');
return *this;
}
Writer&operator<<(const char*s) {
while(*s)pt(*s++);
return *this;
}
} cout;
const int N=500010,inf=20020221;
inline int read() {
register char c=getchar(),d=0;
while(c>'9'||c<'0')d=c,c=getchar();
register int r=0;
while(c>='0'&&c<='9')r=(r<<1)+(r<<3)+c-'0',c=getchar();
return d=='-'?-r:r;
}
inline void wt(int x) {
if(x/10)wt(x/10);
putchar(x%10+'0');
}
inline void wtln(int x) {
if(x<0)x=-x,putchar('-');
wt(x),putchar('\n');
}
inline void wtsp(int x) {
if(x<0)x=-x,putchar('-');
wt(x),putchar(' ');
}
struct edge {
int to,nt,id;
inline void init(int t,int n,int i) {
to=t,nt=n,id=i;
}
} e[N<<1],te[N<<1];
int h[N],c=1,x,y,tc=1,th[N];
inline void addt(int f,int t,int i) {
te[++tc].init(t,th[f],i),th[f]=tc;
te[++tc].init(f,th[t],i),th[t]=tc;
}
inline void adde(int f,int t,int i) {
e[++c].init(t,h[f],i),h[f]=c;
}
int n,m;
int ans[N],tot;
int stp[N],top;
int vis[N];
int ocp[N],del;
inline bool fndc(int pos,int pi=0) {
vis[pos]=1;
register int i,tps;
for(i=h[pos],tps; i; i=e[i].nt) {
tps=e[i].to;
if(e[i].id==pi)continue;
stp[++top]=pos;
if(vis[tps]) {
while(1) {
ocp[stp[top]]=1;
if(stp[top--]==tps)break;
}
return 1;
} else if(fndc(tps,e[i].id))return 1;
if(stp[top]==pos)--top;
}
return 0;
}
int tmp[N],cnt;
inline void dfs(int pos,int nex=inf) {
vis[pos]=1,ans[++tot]=pos;
register int l=cnt,r,i,j;
for(i=h[pos]; i; i=e[i].nt)if(!vis[e[i].to])tmp[cnt++]=e[i].to;
r=cnt;
for(i=l,j=l+1; i<r; i=j,++j) {
if(vis[tmp[i]])continue;
while(j<r&&vis[tmp[j]])++j;
if(j<r)dfs(tmp[i],tmp[j]);
else if(del==0&&ocp[pos]&&ocp[tmp[i]]&&tmp[i]>nex)del=1;
else dfs(tmp[i],nex);
}
}
int main() {
cin>>n>>m;
register int i,pos,x,y;
for(i=1; i<=m; ++i)cin>>x>>y,addt(x,y,i);
for(pos=n; pos>=1; --pos)
for(i=th[pos]; i; i=te[i].nt)
adde(te[i].to,pos,te[i].id);
fndc(1);
memset(vis,0,sizeof vis);
dfs(1);
for(i=1; i<n; ++i)cout<<ans[i]<<" ";
cout<<ans[n]<<endl;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 170.33 us | 1 MB + 996 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 168.59 us | 1 MB + 1000 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #3 | 178.61 us | 1 MB + 1000 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #4 | 176.85 us | 1 MB + 1000 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #5 | 569.49 us | 2 MB + 600 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #6 | 568.76 us | 2 MB + 576 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #7 | 15.118 ms | 14 MB + 232 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #8 | 15.151 ms | 12 MB + 832 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #9 | 208.241 ms | 62 MB + 792 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #10 | 212.661 ms | 66 MB + 484 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #11 | 209.134 ms | 55 MB + 756 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #12 | 214.669 ms | 59 MB + 744 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #13 | 585.04 us | 2 MB + 640 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #14 | 571.32 us | 2 MB + 712 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #15 | 14.331 ms | 15 MB + 428 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #16 | 14.567 ms | 16 MB + 240 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #17 | 212.283 ms | 84 MB + 900 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #18 | 212.352 ms | 84 MB + 900 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #19 | 182.774 ms | 65 MB + 708 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #20 | 200.354 ms | 76 MB + 400 KB | Accepted | Score: 5 | 显示更多 |