05-20 07:35
Recent Posts
Recent Comments
관리 메뉴

너와나의 관심사

백준 문제 2252 본문

카테고리 없음

백준 문제 2252

벤치마킹 2019. 4. 16. 01:59

#include<stdio.h>

#include <stdio.h>

#include <iostream>

#include <queue>

#include <vector>

#include <functional>


using namespace std;

vector<int> adj[32001];

queue<int> q;

int indegree[32001];


int main(){

int N, M;

cin >> N >> M; 

while (M--){

int a, b;

scanf("%d%d", &a, &b);

adj[a].push_back(b);

indegree[b]++;

}


for (int i = 1; i <= N; ++i){

if (indegree[i] == 0)

q.push(i);

}

while (!q.empty())

{

int c = q.front();

printf("%d ", c);

q.pop();

for (int i : adj[c])

{

--indegree[i];

if (indegree[i] == 0)

q.push(i);

}

}

}


Comments