[BOJ] 2252 줄 세우기

Time Lapse :16min 46sec

2252.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <algorithm>
#include <list>
#include <memory.h>
using namespace std;
int n, m, a, b;
bool inLine[32001];
list<int> v[32001];
void push(int n) {
if(inLine[n]) return;
inLine[n] = true;
if(v[n].empty()) {
printf("%d ",n);
return;
}
for(int nt : v[n])
push(nt);
printf("%d ", n);
}
int main() {
scanf("%d %d",&n, &m);
for(int i = 0; i < m; i++) {
scanf("%d %d",&a, &b);
v[b].push_back(a);
}
for(int i = 1; i <= n; ++i)
push(i);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/30/PS/BOJ/2252/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.