#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122
/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK: 20000000005")
*/
using namespace std;
const int N = 1005, M = 100005;
int n, m;
int u[M], v[M];
int G[N][N];
vector < int > g[N];
int par[N], fix[N];
queue < int > Q;
main()
{
//freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= m; i++){
cin >> u[i] >> v[i];
G[u[i]][v[i]] = 1;
G[v[i]][u[i]] = 1;
g[u[i]].pb (v[i]);
g[v[i]].pb (u[i]);
}
for (int I = 1; I <= m; I++){
for (int i = 1; i <= n; i++){
fix[i] = 0;
par[i] = 0;
}
for (int k = 1; k <= n; k++)
if (G[k][u[I]] + G[k][v[I]] == 2)
fix[k] = 1;
Q.push (u[I]);
par[u[I]] = u[I];
while (Q.size() > 0){
int k = Q.front();
Q.pop();
for (int to : g[k]){
if (k == u[I] && to == v[I])
continue;
if (par[to] || fix[to])
continue;
par[to] = k;
Q.push (to);
}
}
if (par[v[I]] == 0)
continue;
cout << u[I] << " ";
int x = v[I];
while (x != u[I]){
cout << x << " ";
x = par[x];
}
return 0;
}
cout << "no" << endl;
return 0;
}
Compilation message
indcyc.cpp:41:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
808 KB |
Output is correct |
2 |
Correct |
11 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
1700 KB |
Output is correct |
2 |
Correct |
4 ms |
1656 KB |
Output is correct |
3 |
Correct |
5 ms |
1740 KB |
Output is correct |
4 |
Correct |
71 ms |
1776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1656 KB |
Output is correct |
2 |
Correct |
81 ms |
1656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
5240 KB |
Output is correct |
2 |
Correct |
49 ms |
4856 KB |
Output is correct |
3 |
Execution timed out |
1057 ms |
5624 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
352 ms |
4792 KB |
Output is correct |
2 |
Execution timed out |
1083 ms |
4856 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
3832 KB |
Output is correct |
2 |
Correct |
271 ms |
4600 KB |
Output is correct |
3 |
Correct |
119 ms |
6136 KB |
Output is correct |
4 |
Execution timed out |
1071 ms |
6092 KB |
Time limit exceeded |