PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000029. Lịch học IV (Course Schedule IV)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Lịch học IV (Course Schedule IV)
Course Schedule IV
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given a directed acyclic graph of course prerequisites, answer whether course is a direct or indirect prerequisite of course for each query.
Input
Integers , then prerequisite edges and queries ; course IDs are .
Output
For each query print true or false.
Subtasks
- Subtask 1 (40 points): ; , , ; unique edges form a DAG; every query has .
- Subtask 2 (60 points): , , ; unique edges form a DAG; every query has .
Examples
Input
3 3 3
1 2
1 0
2 0
1 0
0 2
1 2
Output
true
false
true
Explanation
The edge makes the first query true; there is no route , so the second is false. Edge makes the last true.