/*
بسم الله الرحمن الرحيم
Author:
(:Muhammad Aneeq:)
*/
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
using namespace std;
int const N=2000;
vector<int>nei[N]={};
int vis[N]={};
vector<int>z;
bool check(vector<int>g)
{
map<int,int>cnt;
for (auto i:g)
{
for (auto j:nei[i])
cnt[j]++;
}
for (auto i:g)
{
if (cnt[i]!=2)
return 0;
}
return 1;
}
void ans(vector<int>g)
{
reverse(g.begin(), g.end());
for (auto i:g)
cout<<i<<' ';
cout<<endl;
_Exit(0);
}
void dfs(int x)
{
vis[x]=1;
z.push_back(x);
for (auto i:nei[x])
{
if (vis[i])
{
vector<int>g;
for (int j=z.size()-1;j>=0;j--)
{
g.push_back(z[j]);
if (z[j]==i)
break;
}
if (g.size()>=4&&check(g))
ans(g);
}
else
dfs(i);
}
if (z.size())
z.pop_back();
vis[x]=0;
}
inline void solve()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int a,b;
cin>>a>>b;
nei[a].push_back(b);
nei[b].push_back(a);
}
dfs(2);
cout<<"no\n";
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1059 ms |
604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1039 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1053 ms |
1352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1059 ms |
796 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1012 ms |
1508 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |