# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
391419 | 2021-04-18T17:39:17 Z | qwerasdfzxcl | Mergers (JOI19_mergers) | C++14 | 76 ms | 17628 KB |
#include <bits/stdc++.h> typedef long long ll; using namespace std; vector<int> adj[500500]; int col[500500], cnt[500500], val=0; bool visited[500500], visited2[500500], chk[500500]; unordered_map<int, int> dfs1(int s){ unordered_map<int, int> ret; ret[col[s]] = 1; visited[s]=1; for (auto &v:adj[s]) if (!visited[v]){ auto tmp = dfs1(v); for (auto &p:tmp){ ret[p.first] += p.second; } } chk[s] = 1; for (auto &p:ret){ if (p.second!=cnt[p.first]){ chk[s] = 0; break; } } return ret; } int dfs2(int s){ int ret=0; if (chk[s]) ret++; visited2[s] = 1; for (auto &v:adj[s]) if (!visited2[v]){ ret += dfs2(v); } if (chk[s] && ret==1) val++; return ret; } int main(){ int n, k; scanf("%d %d", &n, &k); for (int i=0;i<n-1;i++){ int a, b; scanf("%d %d", &a, &b); adj[a].push_back(b); adj[b].push_back(a); } for (int i=1;i<=n;i++){ scanf("%d", col+i); cnt[col[i]]++; } dfs1(1); dfs2(1); /*for (int i=1;i<=n;i++) printf("%d ", col[i]); printf("\n"); for (int i=1;i<=n;i++) printf("%d ", cnt[i]); printf("\n"); for (int i=1;i<=n;i++) printf("%d ", chk[i]); printf("\n");*/ printf("%d\n", (val+1)/2); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 11980 KB | Output is correct |
2 | Correct | 8 ms | 12040 KB | Output is correct |
3 | Correct | 8 ms | 11996 KB | Output is correct |
4 | Correct | 8 ms | 12064 KB | Output is correct |
5 | Incorrect | 8 ms | 11980 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 11980 KB | Output is correct |
2 | Correct | 8 ms | 12040 KB | Output is correct |
3 | Correct | 8 ms | 11996 KB | Output is correct |
4 | Correct | 8 ms | 12064 KB | Output is correct |
5 | Incorrect | 8 ms | 11980 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 11980 KB | Output is correct |
2 | Correct | 8 ms | 12040 KB | Output is correct |
3 | Correct | 8 ms | 11996 KB | Output is correct |
4 | Correct | 8 ms | 12064 KB | Output is correct |
5 | Incorrect | 8 ms | 11980 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 76 ms | 17628 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 11980 KB | Output is correct |
2 | Correct | 8 ms | 12040 KB | Output is correct |
3 | Correct | 8 ms | 11996 KB | Output is correct |
4 | Correct | 8 ms | 12064 KB | Output is correct |
5 | Incorrect | 8 ms | 11980 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |