We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
줄 세우기
위상 정렬
### 풀이 언어 - python/java ### 코드 ```python/java ``` ### 핵심 로직 혹은 자료구조 - ### 시간 복잡도 - O( )
The text was updated successfully, but these errors were encountered:
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { private static int n; private static int m; private static List<List<Integer>> nums = new ArrayList<>(); private static int[] check; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); n = Integer.parseInt(st.nextToken()); m = Integer.parseInt(st.nextToken()); for (int i = 0; i <= n; i++) { nums.add(new ArrayList<>()); } check = new int[n+1]; for (int i = 0; i < m; i++) { st = new StringTokenizer(br.readLine()); int num1 = Integer.parseInt(st.nextToken()); int num2 = Integer.parseInt(st.nextToken()); nums.get(num1).add(num2); check[num2]++; } System.out.println(sort()); } private static String sort() { Queue<Integer> queue = new LinkedList<>(); StringBuilder sb = new StringBuilder(); for (int i = 1; i <= n; i++) { if(check[i] == 0) { queue.offer(i); } } while(!queue.isEmpty()) { int num = queue.poll(); sb.append(num).append(" "); for (int index : nums.get(num)) { check[index]--; if(check[index] == 0) { queue.offer(index); } } } return sb.toString(); } }
Sorry, something went wrong.
CMSSKKK
No branches or pull requests
TITLE
줄 세우기
LINK
📷 Screenshots
댓글 양식
The text was updated successfully, but these errors were encountered: