#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=1010, inf=2e9;
int n, m;
vector<int> G0[MX], G1[MX];
vector<pii> E;
bool adj[MX];
void found(int a, int b, int c){
// cout<<a<<' '<<b<<' '<<c<<'\n';
queue<int> ans, Q;
int prv[MX];
for(int i=1; i<=n; i++) prv[i]=-1;
prv[a]=b; Q.push(a);
while(!Q.empty()){
int v=Q.front(); Q.pop();
for(int x:G1[v]){
if(prv[x]>=0) continue;
prv[x]=v;
Q.push(x);
}
}
int v=c;
while(v>0){
ans.push(v); v=prv[v];
}
while(!ans.empty()) cout<<ans.front()<<' ', ans.pop();
cout<<'\n';
exit(0);
}
void search(int st, int out){
bool chk[MX]={};
for(int i=1; i<=n; i++) chk[i]=adj[i], G1[i].clear();
chk[st]=chk[out]=false;
for(pii &e:E){
int u,v; tie(u,v)=e;
if(u==out || v==out) continue;
if(adj[u] && adj[v]){
if(u!=st) swap(u,v);
if(u==st) chk[v]=false;
continue;
}
G1[u].push_back(v);
G1[v].push_back(u);
}
bool vis[MX]={};
vis[st]=true;
queue<int> Q;
Q.push(st);
while(!Q.empty()){
int v=Q.front(); Q.pop();
for(int x:G1[v]){
if(vis[x]) continue;
vis[x]=true;
Q.push(x);
}
}
for(int i=1; i<=n; i++){
if(!chk[i]) continue;
if(vis[i]){
found(st, out, i);
}
}
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
for(int i=1; i<=m; i++){
int u, v; cin>>u>>v;
G0[u].push_back(v);
G0[v].push_back(u);
E.push_back({u,v});
}
for(int v=1; v<=n; v++){
for(int x:G0[v]) adj[x]=true;
for(int x:G0[v]) search(x, v);
for(int x:G0[v]) adj[x]=false;
}
cout<<"no\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
408 KB |
Output is correct |
3 |
Correct |
2 ms |
556 KB |
Output is correct |
4 |
Correct |
3 ms |
556 KB |
Output is correct |
5 |
Correct |
3 ms |
556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
556 KB |
Output is correct |
2 |
Incorrect |
2 ms |
556 KB |
Wrong answer on graph without induced cycle |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
664 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
800 KB |
Output is correct |
2 |
Correct |
4 ms |
800 KB |
Output is correct |
3 |
Incorrect |
4 ms |
800 KB |
Wrong adjacency |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
800 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
435 ms |
2212 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
2212 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1062 ms |
2404 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |