#include<bits/stdc++.h>
using namespace std;
const int maxn=1000+5;
int n,m;
vector<int>adj[maxn],fake[maxn];
vector<int>bf;
int par[maxn];
int mat[maxn][maxn],vis[maxn],visd[maxn],visb[maxn];
vector<int>allv[maxn];
int now=0;
void dfs(int u){
if(visd[u]==1){
return ;
}
visd[u]=1;
if(vis[u]==1){
allv[now].push_back(u);
return ;
}
for(auto x:adj[u]){
dfs(x);
}
}
void bfs(int had){
for(auto x:bf){
if(x==had){
while(x>0){
cout<<x<<" ";
x=par[x];
}
return ;
}
visb[x]=1;
}
//cout<<"salam"<<endl;
vector<int>fakebf;
for(auto x:bf){
for(auto y:fake[x]){
if(visb[y]==0){
visb[y]=1;
par[y]=x;
fakebf.push_back(y);
//cout<<y<<endl;
}
}
}
// cout<<(int)fakebf.size()<<endl;
swap(fakebf,bf);
return bfs(had);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=0;i<m;i++){
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
mat[u][v]=1;
mat[v][u]=1;
}
for(int u=1;u<=n;u++){
for(int i=0;i<maxn;i++){
vis[i]=visd[i]=0;
allv[i].clear();
}
vis[u]=1;
for(auto x:adj[u]){
vis[x]=1;
}
for(int j=1;j<=n;j++){
now=j;
dfs(j);
}
for(int j=1;j<=n;j++){
allv[j].resize(unique(allv[j].begin(),allv[j].end())-allv[j].begin());
}
for(int v=1;v<=n;v++){
for(int i=0;i<(int)allv[v].size();i++){
for(int j=i+1;j<(int)allv[v].size();j++){
if(mat[allv[v][i]][allv[v][j]]==0){
for(int h=0;h<=n;h++){
if(vis[h]==1&&(h!=allv[v][i]&&allv[v][j]!=h)){
continue;
}
// cout<<"asd "<<h<<endl;
for(auto x:adj[h]){
if(vis[x]==1&&(x!=allv[v][i]&&x!=allv[v][j])){
continue;
}
fake[h].push_back(x);
// cout<<h<<" "<<x<<endl;
}
}
// cout<<allv[v][i]<<" "<<allv[v][j]<<" "<<u<<endl;
bf.push_back(allv[v][i]);
bfs(allv[v][j]);
cout<<u<<"\n";
return 0;
}
}
}
}
}
cout<<"no\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
404 KB |
Output is correct |
3 |
Correct |
1 ms |
396 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
392 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
784 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1568 KB |
Output is correct |
2 |
Correct |
2 ms |
1620 KB |
Output is correct |
3 |
Correct |
2 ms |
1748 KB |
Output is correct |
4 |
Correct |
12 ms |
1688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1620 KB |
Output is correct |
2 |
Correct |
8 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
5716 KB |
Output is correct |
2 |
Correct |
16 ms |
5024 KB |
Output is correct |
3 |
Correct |
289 ms |
5280 KB |
Output is correct |
4 |
Correct |
139 ms |
4836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
4812 KB |
Output is correct |
2 |
Correct |
130 ms |
4692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3832 KB |
Output is correct |
2 |
Correct |
19 ms |
3916 KB |
Output is correct |
3 |
Correct |
22 ms |
6292 KB |
Output is correct |
4 |
Correct |
314 ms |
5728 KB |
Output is correct |