일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- stack을 이용한 dfs
- Next
- HTTP
- Prisma
- 백준 9328번
- 백준 9466번
- Github
- string
- PROJECT
- ccw 알고리즘
- localstorage
- 이분 탐색
- MongoDB
- JavaScript
- 백준 28298번
- visual studio code interactive 디버깅
- Express.js
- branch
- 게임 서버 아키텍처
- MySQL
- ERD
- 그리디
- 그래프 탐색
- 자바스크립트
- map
- router
- pm2
- insomnia
- vsc 디버깅
- html5
Archives
- Today
- Total
dh_0e
[PS] 음악 프로그램 / C++ (백준 2623번) 본문
위상 정렬 기초를 다지기 좋은 문제
#include<iostream>
#include<vector>
#include<algorithm>
#include<deque>
using namespace std;
deque<int> dap;
int vi[1001];
int d[1001][1001];
int n, m;
int find()
{
for(int i=1; i<=n; i++){
if(d[i][0]==0&&vi[i]==0){
vi[i]=1;
return i;
}
}
return -1;
}
int main()
{
scanf("%d %d",&n, &m);
for(int i=1; i<=m; i++){
int k, be;
scanf("%d %d",&k, &be);
for(int j=1; j<k; j++){
int c;
scanf("%d",&c);
if(d[c][be]==0)d[c][0]++;
d[c][be]=1;
be=c;
}
}
for(int i=1; i<=n; i++){
int idol=find();
if(idol==-1){
printf("0\n");
return 0;
}
dap.push_back(idol);
for(int j=1; j<=n; j++){
if(d[j][idol]==0)continue;
d[j][0]--;
d[j][idol]=0;
}
}
while(!dap.empty()){
printf("%d\n",dap.front());
dap.pop_front();
}
return 0;
}
'알고리즘 > Baekjoon' 카테고리의 다른 글
[PS] 텀 프로젝트 / C++ (백준 9466번) (0) | 2025.02.04 |
---|---|
[PS] 합이 0인 네 정수 / C++ (백준 7453번) (0) | 2025.02.04 |
[PS] 더 흔한 타일 색칠 문제 / C++ (백준 28298번) (0) | 2024.08.23 |
[PS] 자석 / C++ (백준 28303번) (0) | 2024.08.22 |
[PS] 지금 자면 꿈을 꾸지만 / C++ (백준 32029번) (0) | 2024.08.21 |