이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |