baekjoon 20260421

This commit is contained in:
songyc macbook 2026-04-21 18:10:03 +09:00
parent 3a1ca87a98
commit 38460469fd
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1 @@
print("Leading the Way to the Future" if int(input()) else "YONSEI")

View File

@ -0,0 +1,30 @@
export {};
const input = require("fs").readFileSync(0).toString().trim().split('\n');
const N: number = Number(input[0]);
let graph: number[][] = Array.from({length: N+1}, () => []);
for(let i=1; i<N; i++) {
const [u, v]: number[] = input[i].split(" ").map(Number);
graph[u].push(v);
graph[v].push(u);
}
let visited: boolean[] = new Array(N+1).fill(false);
let dp: number[][] = Array.from({length: N+1}, () => new Array(2).fill(0));
const dfs = (n: number) => {
visited[n] = true;
dp[n][0] = 1;
for(let nxt of graph[n]) {
if(visited[nxt]) continue;
dfs(nxt);
dp[n][1] += dp[nxt][0];
dp[n][0] += Math.min(dp[nxt][0], dp[nxt][1]);
}
};
dfs(1);
console.log(Math.min(dp[1][0], dp[1][1]));