This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 dep[N];
vector<int> g[N];
void dfs(int v, int p, int& x) {
if (dep[v] >= dep[x]) {
x = v;
}
for (int u : g[v]) {
if (u == p) continue;
dep[u] = dep[v] + 1;
dfs(u, v, x);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
int mxdegree = 0;
for(int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
mxdegree = max(mxdegree, (int) g[v].size());
mxdegree = max(mxdegree, (int) g[u].size());
}
dfs(1, 1, a);
dfs(a, a, b);
if (mxdegree >= 3 && dep[b] > 4) {
cout << "NO" << '\n';
return 0;
}
cout << "YES" << '\n';
cout << 1 << '\n';
cout << 1 << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |