/*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 main()
{
ios_base::sync_with_stdio(false);
int n, r;
cin >> n >> r;
while (r--)
{
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int i = 1; i <= n; i++)
{
ieskom(i, -3);
}
cout << "no\n";
}
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
518 ms |
428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1062 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
384 KB |
Output is correct |
2 |
Execution timed out |
1079 ms |
384 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1042 ms |
896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
515 ms |
632 KB |
Output is correct |
2 |
Execution timed out |
1072 ms |
640 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1072 ms |
1280 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |