#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
#define mi(x, y) (x = min(x, y))
#define ma(x, y) (x = max(x, y))
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
vector<vector<int>> way(n);
cin >> n >> m;
vector<int> deg(n);
for(int i = 0; i < m; ++i){
int x, y;
cin >> x >> y;
--x, --y;
++deg[x], ++deg[y];
}
if(m != n - 1){
cout << "NO\n";
return 0;
}
int can = 1;
int rt = -1, mx = -1;
for(int i = 0; i < n; ++i){
if(deg[i] > mx){
mx = deg[i];
rt = i;
}
}
int cnt = 0;
for(auto&nxt:way[rt]){
cnt += (deg[nxt] > 1);
}
if(cnt > 1) can = 0;
for(int i = 0; i < n; ++i){
if(i != rt && deg[i] > 2){
can = 0;
}
}
if(can){
cout << "YES\n1\n1\n";
}
else{
cout << "NO\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |