/*input
5 6
1 2
1 3
2 3
4 3
5 2
4 5
*/
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
vector<int>adj[1010];
vector<int>x;
bool yra[1010];
int pos[1010];
void ieskom(int i, int p)
{
if (yra[i])
return;
pos[i] = x.size();
x.push_back(i);
yra[i] = true;
int maxi = -1;
for (int j : adj[i])
{
if (yra[j] && j != p)
{
maxi = max(maxi, pos[j]);
}
}
if (maxi == -1)
for (int j : adj[i])
{
ieskom(j, i);
}
else
{
vector<int>ciklas;
for (int t = maxi; t < (int)x.size(); t++)
{
ciklas.push_back(x[t]);
}
if (ciklas.size() >= 4)
{
for (int i : ciklas)
cout << i << " ";
exit(0);
}
}
yra[i] = false;
x.pop_back();
}
int pa[1010];
int root(int x)
{
if (pa[x] == x)
return x;
return pa[x] = root(pa[x]);
}
int main()
{
ios_base::sync_with_stdio(false);
int n, r;
cin >> n >> r;
for (int i = 1; i <= n; i++)
pa[i] = i;
while (r--)
{
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
pa[root(a)] = root(b);
}
vector<int>k[n + 1];
for (int i = 1; i <= n; i++)
k[root(i)].push_back(i);
for (int i = 1; i <= n; i++)
{
if (k[i].empty())
continue;
for (int t = 0; t < 20; t++)
{
int j = k[i][rand() % k[i].size()];
ieskom(j, -3);
}
}
cout << "no\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
115 ms |
428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1058 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
512 KB |
Output is correct |
2 |
Execution timed out |
1072 ms |
384 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1063 ms |
896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
640 KB |
Output is correct |
2 |
Execution timed out |
1076 ms |
640 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
1384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |