Submission #680440

#TimeUsernameProblemLanguageResultExecution timeMemory
680440qwerasdfzxclWells (CEOI21_wells)C++17
0 / 100
37 ms71896 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; int dist[10010][10010], vcnt, n, k; vector<int> adj[1501500], G[1501500], st; vector<vector<int>> path; void dfs(int s, int pa = -1){ st.push_back(s); if ((int)st.size()==k) path.push_back(st); dist[st[0]][s] = (int)st.size() - 1; for (auto &v:adj[s]) if (v!=pa){ dfs(v, s); } st.pop_back(); } int col[1501500]; int simulate(int s){ vector<int> q = {s}, ch = {s}; col[s] = 1; while(!q.empty()){ int v = q.back(); q.pop_back(); for (int i=1;i<=n;i++) if (dist[v][i]==k && !col[i]){ col[i] = 1; q.push_back(i); ch.push_back(i); } } int ret = 1; for (auto &p:path){ int cnt = 0; for (auto &x:p) if (col[x]) cnt++; if (cnt>1){ for (auto &x:ch) col[x] = 0; return 0; } if (cnt==0) ret = -1; } return ret; } int main(){ scanf("%d %d", &n, &k); for (int i=1;i<=n-1;i++){ int x, y; scanf("%d %d", &x, &y); adj[x].push_back(y); adj[y].push_back(x); } for (int i=1;i<=n;i++){ dfs(i); } for (int i=1;i<=n;i++) if (simulate(i)==1){ printf("YES\n0\n"); return 0; } printf("NO\n0\n"); return 0; }

Compilation message (stderr)

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