Submission #532008

#TimeUsernameProblemLanguageResultExecution timeMemory
532008abc864197532Unique Cities (JOI19_ho_t5)C++17
4 / 100
266 ms3288 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mp make_pair #define eb emplace_back #define pb push_back #define pii pair<int,int> #define X first #define Y second #define all(x) x.begin(), x.end() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T i, U ...j) { cout << i << ' ', abc(j...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } #ifdef Doludu #define test(x...) abc("[" + string(#x) + "]", x) #define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #else #define test(x...) void(0) #define owo ios::sync_with_stdio(false), cin.tie(0) #endif const int N = 2001; vector <int> adj[N]; vector <int> f[N]; void dfs(int v, int pa, int d = 0) { f[d].pb(v); for (int u : adj[v]) if (u != pa) { dfs(u, v, d + 1); } } int main () { owo; int n, m; cin >> n >> m; for (int i = 0, u, v; i < n - 1; ++i) { cin >> u >> v, --u, --v; adj[u].pb(v), adj[v].pb(u); } vector <int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) { for (int i = 0; i <= n; ++i) f[i].clear(); dfs(i, -1); set <int> S; for (int i = 1; i <= n; ++i) { if (f[i].size() == 1) S.insert(a[f[i][0]]); } cout << S.size() << '\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...