#include <bits/stdc++.h>
#define pb push_back
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define mid (l+r)/2
#define inf 1e15
#define MOD 998244353
#define MX 1005
using namespace std;
vi edges[MX], ans;
bitset<MX> adj[MX], last;
int vis[MX], revis[MX];
int tim=0;
int dfs(int node, int par){
//cerr << node+1 spc par+1 << endl;
vis[node]=++tim;
revis[tim]=node;
int can=-1;
for(auto i:edges[node]){
if(i==par) continue;
if(vis[i]>0){
auto dont=adj[node];
dont&=adj[par];
if(node!=0 && dont[i]==1) continue;
if(can==-1 || vis[i]>vis[can]){
auto wow=adj[i];
for(int j=vis[i]; j<vis[node]; j++){
wow&=adj[revis[j]];
}
if(wow[node]==0){
can=i;
}
}
}
}
if(can!=-1){
ans.pb(node+1);
last|=adj[node];
return can;
}
for(auto i:edges[node]){
if(i==par) continue;
if(vis[i]!=0) continue;
int res=dfs(i, node);
if(res==-2) return -2;
if(res!=-1){
if(node==res){
ans.pb(node+1);
return -2;
}
auto dont=adj[node];
dont&=last;
if(par==res || dont[par]==0){
ans.pb(node+1);
last|=adj[node];
}
return res;
}
}
vis[node]=-1;
return -1;
}
int dfs2(int node, int par){
vis[node]=++tim;
int can=-1;
for(auto i:edges[node]){
if(i==par) continue;
if(vis[i]>0){
if(can==-1 || vis[i]>vis[can]) can=i;
}
}
if(can!=-1){
cout << node+1 << " ";
return can;
}
for(auto i:edges[node]){
if(i==par) continue;
if(vis[i]!=0) continue;
auto dont=adj[node];
dont&=adj[par];
if(node!=par && dont[i]==1) continue;
int res=dfs2(i, node);
if(res==-2) return -2;
if(res!=-1){
cout << node+1 << " ";
if(node!=res) return res;
else return -2;
}
}
vis[node]=-1;
return -1;
}
void solve(){
int n,m; cin >> n >> m;
last.reset();
for(int i=0; i<n; i++){
adj[MX].reset();
vis[i]=0;
}
for(int i=1; i<=m; i++){
int a,b; cin >> a >> b; a--, b--;
edges[a].pb(b);
edges[b].pb(a);
adj[a].set(b);
adj[b].set(a);
}
if(dfs2(0,0)!=-1){
for(auto i:ans) cout << i << " ";
return;
}
memset(vis, 0, sizeof(vis));
tim=0;
ans.clear();
if(dfs(0,0)==-1 || ans.size()<4) cout << "no" << endl;
else for(auto i:ans) cout << i << " ";
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
/*#else
freopen("","r",stdin);
freopen("","w",stdout);*/
#endif
int t=1;
//cin >> t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Wrong answer on graph without induced cycle |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Incorrect |
2 ms |
592 KB |
Wrong answer on graph without induced cycle |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
592 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1616 KB |
Output is correct |
2 |
Correct |
3 ms |
1108 KB |
Output is correct |
3 |
Incorrect |
6 ms |
1616 KB |
Wrong answer on graph without induced cycle |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
1104 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
2384 KB |
Output is correct |
2 |
Correct |
13 ms |
2640 KB |
Output is correct |
3 |
Correct |
14 ms |
2132 KB |
Output is correct |
4 |
Incorrect |
8 ms |
2128 KB |
Wrong answer on graph without induced cycle |
5 |
Halted |
0 ms |
0 KB |
- |