이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |