제출 #587084

#제출 시각아이디문제언어결과실행 시간메모리
587084Justin1Unique Cities (JOI19_ho_t5)C++14
4 / 100
358 ms716 KiB
#include <bits/stdc++.h> using namespace std; int n,m,k,x,y,z; int c[2005], v[2005], d[2005], ok[2005]; vector<int> gph[2005]; void dfs(int id, int dis) { v[id] = 1; d[id] = dis; for (auto i : gph[id]) { if (!v[i]) dfs(i,dis+1); } } int main() { cin.tie(0), cout.tie(0) -> sync_with_stdio(0); cin >> n >> m; for (int i = 1; i < n; i++) { cin >> x >> y; gph[x].push_back(y); gph[y].push_back(x); } for (int i = 1; i <= n; i++) cin >> c[i]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) v[j] = ok[j] = 0; dfs(i,0); pair<int,int> ar[2005]; for (int j = 1; j <= n; j++) ar[j] = {d[j],j}; sort(ar+1,ar+1+n); int ans = 0; for (int j = 1; j <= n; j++) if (ar[j].first != ar[j-1].first && ar[j].first != ar[j+1].first) { ok[c[ar[j].second]] = 1; } for (int j = 1; j <= n; j++) ans += ok[j]; cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...