baekjoon 20260421
This commit is contained in:
parent
3a1ca87a98
commit
38460469fd
1
code_study/Baekjoon/python/15680.py
Normal file
1
code_study/Baekjoon/python/15680.py
Normal file
@ -0,0 +1 @@
|
||||
print("Leading the Way to the Future" if int(input()) else "YONSEI")
|
||||
30
code_study/Baekjoon/ts/2533.ts
Normal file
30
code_study/Baekjoon/ts/2533.ts
Normal 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]));
|
||||
Loading…
x
Reference in New Issue
Block a user