| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 210176 | arman_ferdous | Mergers (JOI19_mergers) | C++17 | 75 ms | 30956 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5e5+10;
int n, k, c[N];
vector<int> g[N], node[N];
int cur, vis[N], comp[N];
set<int> st;
int p[N];
void dfs(int u, int f) {
p[u] = f;
for(int v : g[u]) if(v != f)
dfs(v, u);
}
void up(int u) {
if(vis[u] != 0) return;
vis[u] = cur;
st.insert(c[u]);
if(p[u] + 1) up(p[u]);
}
void process() {
while(!st.empty()) {
int x = *st.begin();
st.erase(st.begin());
for(int u : node[x])
up(u);
node[x].clear();
}
}
int deg[N];
int main() {
scanf("%d %d", &n, &k);
for(int i = 1; i < n; i++) {
int u, v; scanf("%d %d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1, -1);
for(int i = 1; i <= n; i++) {
scanf("%d", &c[i]);
node[c[i]].push_back(i);
}
for(int i = 1; i <= k; i++) if(!node[i].empty()) {
cur++;
st.insert(i);
process();
}
for(int i = 2; i <= n; i++) if(vis[p[i]] != vis[i]) {
deg[vis[p[i]]]++;
deg[i]++;
}
int leaf = 0;
for(int i = 1; i <= n; i++) if(deg[i] == 1) leaf++;
if(leaf == 0) puts("0");
else printf("%d\n", (leaf - 1) / 2 + 1);
return 0;
}
컴파일 시 표준 에러 (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... | ||||
