#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1005;
const int LOG = 14;
vector<int> T[N];
bool vis[N];
int dep[N];
int cc;
int par[N];
int high[N];
void dfs(int u, int pp){
par[u] = pp;
vis[u]=true;
for(auto x : T[u]){
if(x == pp){
continue;
}
if(vis[x]) {
high[u] = max(high[u], dep[x]);
continue;
}
dep[x]=dep[u]+1;
dfs(x, u);
}
}
int main(){
fastIO;
int n, m;
cin >> n >> m;
int u, v;
for(int i = 0 ; i < m ; i ++ ){
cin >> u >> v;
T[u].push_back(v);
T[v].push_back(u);
}
vector<int> pash;
for(int i = 1; i <= n; i ++ )
pash.push_back(i);
for(int it = 0; it < 200; it ++ ){
random_shuffle(pash.begin(), pash.end());
for(int j = 1; j <= n; j ++ ){
vis[j]=false;
high[j]=-1;
}
for(auto i : pash ){
if(vis[i]) continue;
dfs(i,i);
}
int node;
bool good;
for(int i = 1; i <= n; i ++ ){
for(auto x : T[i]){
if(dep[i] - dep[x] + 1 >= 4){
node = i;
good = true;
while(node != x){
if(node == i){
if(high[i] > dep[x]){
good = false;
break;
}
}
else if(high[node] >= dep[x]){
good = false;
break;
}
node = par[node];
}
if(good){
node = i;
while(1){
cout << node << " ";
if(node == x) break;
node = par[node];
}
return 0;
}
}
}
}
}
cout << "no\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
384 KB |
Output is correct |
2 |
Incorrect |
11 ms |
384 KB |
Expected integer, but "no" found |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
384 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
131 ms |
896 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
640 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
222 ms |
1404 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |