20250715 baekjoon
This commit is contained in:
parent
6796fb6dc4
commit
7de948add1
17
code_study/Baekjoon/python/2606.py
Normal file
17
code_study/Baekjoon/python/2606.py
Normal file
@ -0,0 +1,17 @@
|
||||
N = int(input())
|
||||
link = [[] for _ in range(N+1)]
|
||||
visited = [False] * (N+1)
|
||||
|
||||
for _ in range(int(input())):
|
||||
a, b = map(int, input().split())
|
||||
link[a].append(b)
|
||||
link[b].append(a)
|
||||
|
||||
def dfs(now) :
|
||||
visited[now] = True
|
||||
for nt in link[now] :
|
||||
if not visited[nt] :
|
||||
dfs(nt)
|
||||
|
||||
dfs(1)
|
||||
print(visited.count(True)-1)
|
||||
7
code_study/Baekjoon/python/9095.py
Normal file
7
code_study/Baekjoon/python/9095.py
Normal file
@ -0,0 +1,7 @@
|
||||
dp = [0]*11
|
||||
dp[1:3] = [1,2,4]
|
||||
for i in range(4,11):
|
||||
dp[i] = dp[i-1] + dp[i-2] + dp[i-3]
|
||||
|
||||
for _ in range(int(input())):
|
||||
print(dp[int(input())])
|
||||
24
code_study/Baekjoon/ts/2606.ts
Normal file
24
code_study/Baekjoon/ts/2606.ts
Normal file
@ -0,0 +1,24 @@
|
||||
export {};
|
||||
|
||||
const input: string[] = require("fs").readFileSync(0, "utf8").toString().trim().split('\n')
|
||||
let link = Array.from({length : Number(input[0])+1}, () => []);
|
||||
let visited = new Array(Number(input[0])+1).fill(false);
|
||||
input.slice(2).forEach(v => {
|
||||
const [a,b] = v.split(" ").map(Number);
|
||||
link[a].push(b);
|
||||
link[b].push(a);
|
||||
});
|
||||
|
||||
const dfs = (now: number) => {
|
||||
visited[now] = true;
|
||||
for(let nt of link[now]){
|
||||
if(!visited[nt]){
|
||||
dfs(nt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dfs(1);
|
||||
let count: number = 0;
|
||||
visited.forEach((v)=>{if(v) count++;});
|
||||
console.log(count-1);
|
||||
Loading…
x
Reference in New Issue
Block a user