Submission #99717

#TimeUsernameProblemLanguageResultExecution timeMemory
99717cki86201Unique Cities (JOI19_ho_t5)C++11
4 / 100
130 ms16460 KiB
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include <math.h> #include <assert.h> #include <stack> #include <queue> #include <map> #include <set> #include <string> #include <algorithm> #include <iostream> #include <functional> #include <unordered_set> #include <bitset> #include <time.h> #include <limits.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define Fi first #define Se second #define pb(x) push_back(x) #define szz(x) (int)x.size() #define rep(i,n) for(int i=0;i<n;i++) #define all(x) x.begin(),x.end() typedef tuple<int, int, int> t3; int N, M; vector <int> E[2020]; int C[2020]; int dis[2020][2020]; int main() { scanf("%d%d", &N, &M); if(N > 2000) return 0; for(int i=1;i<N;i++) { int x, y; scanf("%d%d", &x, &y); E[x].pb(y); E[y].pb(x); } 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++) dis[i][j] = -1; dis[i][i] = 0; vector <int> q; q.pb(i); rep(a, szz(q)) { int t = q[a]; for(int e : E[t]) if(dis[i][e] == -1) { dis[i][e] = dis[i][t] + 1; q.pb(e); } } int cnt[2020] = {}, er[2020] = {}; for(int j=1;j<=N;j++) cnt[dis[i][j]]++; int ans = 0; for(int j=1;j<=N;j++) if(j != i && cnt[dis[i][j]] == 1) { if(er[C[j]] == 0) er[C[j]] = 1, ++ans; } printf("%d\n", ans); } return 0; }

Compilation message (stderr)

joi2019_ho_t5.cpp: In function 'int main()':
joi2019_ho_t5.cpp:38: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:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d%d", &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~
joi2019_ho_t5.cpp:44:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=N;i++) 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...