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;
#define int long long
vector<int> adj[500];
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
int n, k; cin>>n>>k;
for(int i=0; i<n-1; i++)
{
int x, y; cin>>x>>y;
adj[x].push_back(y);
}
vector<int> vis(n+1);
priority_queue<array<int, 2>> q;
q.push({1, 1});
int t=0;
vis[1]=1;
if(adj[1].size()>0)
while(q.size())
{
priority_queue<array<int, 2>> q2;
vis[q.top()[1]]=1;
if(q.top()[1]!=1)
q.pop();
if(q.size()) t++;
while(q.size())
{
vis[q.top()[1]]=1;
for(auto i: adj[q.top()[1]])
{
if(!vis[i])
q2.push({(int)(adj[i].size()), i}), vis[i]=1;
}
q.pop();
}
q=q2;
}
if(t<=k) cout<<"DA";
else cout<<"NE";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |