Submission #674535

#TimeUsernameProblemLanguageResultExecution timeMemory
674535Nicolas125841Burza (COCI16_burza)C++14
0 / 160
1 ms344 KiB
#include <bits/stdc++.h> using namespace std; #define YES "DA" #define NO "NE" int dfs(vector<vector<int>> &mp, int n, int p, int m){ if(mp[n].size() == 1 && mp[n][0] == p) return m+1; else{ vector<int> ans; for(int v : mp[n]) if(v != p) ans.push_back(dfs(mp, v, n, m+1)); sort(ans.begin(), ans.end()); if(ans.size() == 1) return m+1; else return ans[ans.size()-2]; } } int main(){ cin.tie(NULL)->sync_with_stdio(false); int n, k; cin >> n >> k; vector<vector<int>> mp(n, vector<int>()); for(int i = 0; i < n-1; i++){ int u, v; cin >> u >> v; mp[--u].push_back(--v); mp[v].push_back(u); } cout << (dfs(mp, 0, -1, 0) <= k ? YES : NO) << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...