# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
104739 | Hideo | Mergers (JOI19_mergers) | C++14 | 230 ms | 263168 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define vl vector < ll >
#define pi pair < int, int >
#define pii pair < int, pi >
#define vii vector < pi >
const int N = 5e5 + 7;
const int mod = 1e9 + 7;
int us[N], a[N], b[N], m[N], cur[N];
int n, k, gr = 1, ans;
vi g[N], t[N];
void dfs (int v = 1, int p = 0){
for (int to : g[v]){
if (to != p){
dfs(to, v);
cur[v] += cur[to];
}
}
us[a[v]]++;
if (us[a[v]] == 1)
cur[v]--;
if (us[a[v]] == m[a[v]]){
cur[v]++;
us[a[v]] = 0;
}
b[v] = gr;
if (cur[v] == 0)
gr++;
for (int to : g[v]){
if (to != p && b[to] != b[v]){
t[b[v]].pb(b[to]);
t[b[to]].pb(b[v]);
}
}
}
void findAns (int v = 1, int p = 0){
if (t[v].size() == 1)
ans++;
for (int to : t[v])
if (to != p)
findAns(to, v);
}
main(){
cin >> n >> k;
for (int i = 1; i < n; i++){
int a, b;
scanf("%d%d", &a, &b);
g[a].pb(b);
g[b].pb(a);
}
for (int i = 1; i <= n; i++){
scanf("%d", &a[i]);
m[a[i]]++;
}
dfs();
findAns();
printf("%d", (ans + 1) / 2);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |