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;
int n,m;
vector<int> g[1005],f[1005];
int h[1005];
int hmax[1005];
void dfs(int nod,int tata)
{
hmax[nod] = h[nod];
for (auto vecin : g[nod])
{
if (vecin != tata)
{
h[vecin] = 1 + h[nod];
f[nod].push_back(vecin);
dfs(vecin,nod);
hmax[nod] = max(hmax[nod],hmax[vecin]);
}
}
}
bool nod_sussy(int x)
{
for (int i = 1; i <= n; i++)
f[i].clear();
h[x] = 0;
dfs(x,0);
int cnt = 0;
for (auto fiu : f[x])
if (hmax[fiu] >= 3)
cnt++;
if (cnt >= 3)
return true;
return false;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
int x,y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
if (m != n - 1)
{
cout << "NO";
return 0;
}
for (int i = 1; i <= n; i++)
{
if (nod_sussy(i))
{
cout << "NO";
return 0;
}
}
cout << "YES\n1\n1";
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... |