Submission #202613

#TimeUsernameProblemLanguageResultExecution timeMemory
202613dndhkUnique Cities (JOI19_ho_t5)C++14
4 / 100
2037 ms16120 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAX_N = 200000; int N, M; int c[MAX_N+1]; vector<int> gp[MAX_N+1]; int vst[MAX_N+1]; int lv[MAX_N+1], p[MAX_N+1]; int cnt[MAX_N+1]; set<int> st; void dfs(int x){ cnt[lv[x]]++; for(int i : gp[x]){ if(i==p[x]) continue; p[i] = x; lv[i] = lv[x]+1; dfs(i); } } int main(){ scanf("%d%d", &N, &M); for(int i=1; i<N; i++){ int a, b; scanf("%d%d", &a, &b); gp[a].pb(b); gp[b].pb(a); } for(int i=1; i<=N; i++){ scanf("%d", &c[i]); } for(int i=1; i<=N; i++){ for(int j=1; j<=N; j++) cnt[j] = vst[j] = lv[j] = p[j] = 0; lv[i] = 1; dfs(i); st.clear(); for(int j=1; j<=N; j++){ if(i==j) continue; if(cnt[lv[j]]==1){ st.insert(c[j]); } } printf("%d\n", (int)st.size()); } return 0; }

Compilation message (stderr)

joi2019_ho_t5.cpp: In function 'int main()':
joi2019_ho_t5.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
joi2019_ho_t5.cpp:36:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d%d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~
joi2019_ho_t5.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &c[i]);
   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...