Submission #680292

#TimeUsernameProblemLanguageResultExecution timeMemory
680292mjhmjh1104Wells (CEOI21_wells)C++17
0 / 100
20 ms35540 KiB
#include <cstdio> #include <vector> #include <utility> #include <algorithm> using namespace std; int n, k, K, b[1500006]; vector<int> adj[1500006]; bool dfs(int x, int dist, int prev = -1) { if (b[x]) { if (dist != -1 && dist % K) return false; dist = 0; } int ndist = dist; if (ndist != -1) ndist++; for (auto &i: adj[x]) if (i != prev && !dfs(i, ndist, x)) return false; return true; } int main() { scanf("%d%d", &n, &k); K = k; if (k % 2 == 0) K /= 2; for (int i = 0; i < n - 1; i++) { int u, v; scanf("%d%d", &u, &v); u--, v--; adj[u].push_back(v); adj[v].push_back(u); } for (int i = 0; i < n; i++) if ((int)adj[i].size() > 2) b[i] = 1; if (!dfs(0, -1)) puts("NO\n0"); else puts("YES\n1"); }

Compilation message (stderr)

wells.cpp: In function 'int main()':
wells.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~
wells.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...