#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 2e5 + 5;
int a, b;
int pr[N];
int dep[N];
bool vis[N];
bool mark[N];
vector<int> g[N];
void check(int v, int p) {
vis[v] = true;
if (dep[v] >= dep[a]) {
a = v;
}
for (int u : g[v]) {
if (u == p) continue;
if (vis[u]) {
cout << "NO" << '\n';
exit(0);
}
dep[u] = dep[v] + 1;
check(u, v);
}
}
void dfs(int v, int p) {
if (dep[v] >= dep[b]) {
b = v;
}
for (int u : g[v]) {
if (u == p) continue;
dep[u] = dep[v] + 1;
pr[u] = v;
dfs(u, v);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for(int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
check(1, 1);
dep[a] = 0;
dfs(a, a);
int x = b;
while (x) {
mark[x] = true;
x = pr[x];
}
//for (int i = 1; i <= n; ++i) {
//if (g[i].size() > 1 && !mark[i]) {
//cout << "NO" << '\n';
//return 0;
//}
//}
cout << "YES" << '\n';
cout << 1 << '\n';
cout << 1 << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
3 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
4 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
5 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
6 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
9 |
Incorrect |
1 ms |
6748 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Partially correct |
2 ms |
6748 KB |
Failed to provide a successful strategy. |
3 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
4 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
5 |
Partially correct |
2 ms |
6756 KB |
Failed to provide a successful strategy. |
6 |
Partially correct |
1 ms |
6744 KB |
Failed to provide a successful strategy. |
7 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
8 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
9 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
10 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
11 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
12 |
Partially correct |
2 ms |
6748 KB |
Failed to provide a successful strategy. |
13 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
14 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
15 |
Partially correct |
2 ms |
6748 KB |
Failed to provide a successful strategy. |
16 |
Partially correct |
2 ms |
6744 KB |
Failed to provide a successful strategy. |
17 |
Partially correct |
2 ms |
6748 KB |
Failed to provide a successful strategy. |
18 |
Partially correct |
2 ms |
6748 KB |
Failed to provide a successful strategy. |
19 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
20 |
Partially correct |
2 ms |
6748 KB |
Failed to provide a successful strategy. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
3 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
4 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
5 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
6 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Partially correct |
1 ms |
6748 KB |
Failed to provide a successful strategy. |
9 |
Incorrect |
1 ms |
6748 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |