#include<cstdio>
#include<cstring>
#include<queue>
bool isin[5555];
int n,m;
struct edge
{int p,t;bool flag;}e[22222];
int asw[5555],tot,h[5555];
inline void build(int x,int y)
{e[++tot]=(edge){h[x],y,0},h[x]=tot;}
int low,from[5555],d[5555];
int tp,stk[5555];
bool vis[5555];
int argv[5555][5555];
int argc[5555];
bool flag[5555][5555];
std::priority_queue<int>Q;
inline int dfs(int s=1,bool need=1)
{
stk[++tp]=s;
if(stk[tp]<asw[tp])need=0;
if(need&&(stk[tp]>asw[tp]))return 0;
vis[s]=1;
for(register int i=1;i<=argc[s];i++)
{
int to=argv[s][i];
if(flag[s][to])continue;
if(vis[to])continue;
int t=dfs(to,need);
if(!t)return 0;
else if(t==2)need=0;
}if(!need)return 2;
else return 1;
}
int x[5555],y[5555];
inline void cnter()
{
register int i,ii,iii;
for(i=1;i<=n;i++)
{
for(ii=h[i];ii;ii=e[ii].p)
{
int to=e[ii].t;
Q.push(-to);
}
for(;Q.size();)
{argv[i][++argc[i]]=-Q.top();Q.pop();}
}
asw[1]=2;
if(m==n-1)
{
dfs();
for(i=1;i<=n;i++)
asw[i]=stk[i];
}
else
{
for(i=1;i<=m;i++)
{
tp=0;
flag[x[i]][y[i]]=flag[y[i]][x[i]]=1;
memset(vis,0,sizeof(vis));
dfs();
if(tp==n)
{
for(ii=1;ii<=n;ii++)
{
if(asw[ii]>stk[ii])
{
for(iii=1;iii<=n;iii++)
asw[iii]=stk[iii];
break;
}
else if(asw[ii]<stk[ii])break;
}
}
flag[x[i]][y[i]]=flag[y[i]][x[i]]=0;
}
}
for(i=1;i<n;i++)
printf("%d ",asw[i]);
printf("%d\n",asw[n]);
}
int main()
{
register int i;
scanf("%d%d",&n,&m);
isin[1]=1;
for(i=1;i<=m;i++)
{
scanf("%d%d",&x[i],&y[i]);
d[x[i]]++,d[y[i]]++;
build(x[i],y[i]),build(y[i],x[i]);
}
cnter();
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 23.42 us | 108 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 25.85 us | 108 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 23.26 us | 108 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 85.88 us | 480 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 85.47 us | 472 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 738.43 us | 4 MB + 84 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 738.72 us | 4 MB + 88 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 740.13 us | 4 MB + 92 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 733.68 us | 4 MB + 64 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 733.86 us | 4 MB + 60 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 3.827 ms | 20 MB + 48 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 3.841 ms | 20 MB + 100 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 3.865 ms | 20 MB + 136 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 3.823 ms | 20 MB + 48 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 3.87 ms | 20 MB + 176 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 26.59 us | 148 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 26.97 us | 148 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 123.06 us | 880 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 123.94 us | 880 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 1.316 ms | 8 MB + 280 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 1.295 ms | 8 MB + 336 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 10.621 ms | 8 MB + 360 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 8.3 ms | 43 MB + 220 KB | Accepted | Score: 4 | 显示更多 |
Testcase #24 | 7.526 ms | 42 MB + 940 KB | Accepted | Score: 4 | 显示更多 |
Testcase #25 | 6.359 ms | 42 MB + 804 KB | Accepted | Score: 4 | 显示更多 |