#include <bits/stdc++.h>
using namespace std;
#define pi pair<int, int>
#define f first
#define s second
int n;
int par[1005][1005], visited[1005][1005];
bool edge[1005][1005];
void dfs(int a, int b){
visited[a][b] = 1;
for(int i = 1; i <= n; i++){
if(i == a || edge[a][i] || !edge[b][i]) continue;
if(visited[b][i] == 1){
vector <int> cycle;
cycle.push_back(b);
cycle.push_back(a);
while(a != i){
cycle.push_back(par[a][b]);
int tmp = par[a][b];
b = a;
a = tmp;
}
int sz = cycle.size();
int l = 0, r = sz - 1;
for(int j = 0; j < sz; j++){
for(int k = j + 2; k < sz; k++){
if(edge[cycle[j]][cycle[k]]){
if(r - l > k - j){
l = j;
r = k;
}
}
}
}
for(int j = l; j <= r; j++) cout << cycle[j] << " ";
cout << endl;
return ;
}else if(!visited[b][i]){
par[b][i] = a;
dfs(b, i);
}
}
visited[a][b] = 2;
}
int main(){
int r;
cin >> n >> r;
vector <pi> edges;
while(r--){
int a, b; cin >> a >> b;
edge[a][b] = true;
edge[b][a] = true;
edges.push_back({a, b});
}
for(auto i : edges){
if(!visited[i.f][i.s]){
//cout << endl;
dfs(i.f, i.s);
}
}
cout << "no"<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1102 ms |
525988 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1064 ms |
526756 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
860 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3160 KB |
Output is correct |
2 |
Execution timed out |
1081 ms |
528296 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2136 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1040 ms |
534832 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1055 ms |
532224 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
5232 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |