Submission #532545

#TimeUsernameProblemLanguageResultExecution timeMemory
53254579brueNewspapers (CEOI21_newspapers)C++14
50 / 100
85 ms472 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, m; vector<int> link[1002]; int dfs(int x, int par = -1){ vector<int> vec (1, 0); for(auto y: link[x]){ if(y==par) continue; int tmp = dfs(y, x); vec.push_back(tmp+1); } sort(vec.rbegin(), vec.rend()); if(par == -1){ if(vec.size() >= 3 && vec[2] >= 3){ puts("NO"); exit(0); } } return vec[0]; } int main(){ scanf("%d %d", &n, &m); if(m!=n-1){ puts("NO"); return 0; } for(int i=1; i<n; i++){ int x, y; scanf("%d %d", &x, &y); link[x].push_back(y), link[y].push_back(x); } for(int i=1; i<=n; i++){ dfs(i); } printf("YES\n2\n1 1"); }

Compilation message (stderr)

newspapers.cpp: In function 'int main()':
newspapers.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
newspapers.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...