baekjoon 20251202
This commit is contained in:
parent
11abda6b56
commit
947cd4a91c
34
code_study/Baekjoon/ts/2623.ts
Normal file
34
code_study/Baekjoon/ts/2623.ts
Normal file
@ -0,0 +1,34 @@
|
||||
export {};
|
||||
|
||||
const input = require("fs").readFileSync(0).toString().trim().split('\n');
|
||||
const [N, M]: number[] = input[0].split(" ").map(Number);
|
||||
|
||||
let graph: number[][] = Array.from({length: N+1}, () => []);
|
||||
let inDegree: number[] = new Array(N+1).fill(0);
|
||||
for(let i=1; i<=M; i++) {
|
||||
const line: number[] = input[i].split(" ").map(Number);
|
||||
|
||||
for(let j=1; j<line[0]; j++) {
|
||||
const [u, v]: number[] = [line[j], line[j+1]];
|
||||
graph[u].push(v);
|
||||
inDegree[v]++;
|
||||
}
|
||||
}
|
||||
|
||||
let qu: number[] = [];
|
||||
let idx: number = 0;
|
||||
for(let n=1; n<=N; n++) {
|
||||
if (inDegree[n] === 0) qu.push(n);
|
||||
}
|
||||
|
||||
while (idx < qu.length) {
|
||||
const current: number = qu[idx++];
|
||||
|
||||
for(let next of graph[current]) {
|
||||
inDegree[next]--;
|
||||
if(inDegree[next] === 0) qu.push(next);
|
||||
}
|
||||
}
|
||||
|
||||
if (qu.length < N) console.log(0);
|
||||
else console.log(qu.join("\n"));
|
||||
Loading…
x
Reference in New Issue
Block a user