#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) ((int)size(x))
#define trace(x) cout << #x << ": " << (x) << endl;
typedef long long ll;
const int N = 1000;
bool e[N][N];
int depth[N];
vector<int> st;
int n;
bool used[N];
vector<int> g[N];
void dfs(int v, int p, int d) {
used[v] = true;
st.push_back(v);
depth[v] = d;
int gg = -1;
for (int to:g[v]) {
if (to != p && depth[to]) {
if (gg == -1 || depth[to] > depth[gg]) {
gg = to;
}
}
}
if (gg != -1) {
cout << gg + 1 << " ";
while (st.back() != gg) {
cout << st.back() + 1 << " ";
st.pop_back();
}
exit(0);
}
for (int to: g[v]) {
if (to != p && !e[p][to] && !used[to]) {
dfs(to, v, d + 1);
}
}
st.pop_back();
depth[v] = false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int r;
cin >> n >> r;
for (int i = 0; i < r; ++i) {
int a, b;
cin >> a >> b;
--a, --b;
e[a][b] = e[b][a] = true;
g[a].push_back(b);
g[b].push_back(a);
}
for (int v = 0; v < n; ++v) {
memset(used, 0, sizeof(used));
depth[v] = true;
st.push_back(v);
for (int to: g[v]) {
dfs(to, v, 2);
}
st.pop_back();
depth[v] = false;
}
cout << "no";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
356 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
728 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
704 KB |
Output is correct |
4 |
Correct |
15 ms |
772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
716 KB |
Output is correct |
2 |
Correct |
14 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
2004 KB |
Output is correct |
2 |
Correct |
6 ms |
1772 KB |
Output is correct |
3 |
Correct |
356 ms |
2224 KB |
Output is correct |
4 |
Correct |
196 ms |
1776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
1680 KB |
Output is correct |
2 |
Correct |
170 ms |
1748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
205 ms |
2032 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |