PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000042. Lược bỏ điều kiện tiên quyết thừa (No More Prerequisites, Please!)
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ược bỏ điều kiện tiên quyết thừa (No More Prerequisites, Please!)
No More Prerequisites, Please!
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Given a DAG of direct prerequisites, an edge is redundant if another path with at least one intermediate course exists. Output all nonredundant direct edges in sorted order.
Input
Integers and directed edges meaning course is a direct prerequisite of course .
Output
Print the number of nonredundant prerequisite edges, followed by one u v pair per line in increasing order of u, then v.
Subtasks
- Subtask 1 (40 points): ; , ; 1-indexed vertices, unique edges forming a DAG.
- Subtask 2 (60 points): , ; 1-indexed vertices, unique edges forming a DAG.
Examples
Input
4 4
1 2
2 3
1 3
3 4
Output
3
1 2
2 3
3 4
Explanation
The edge 1 to 3 is redundant because 1 to 2 to 3 already exists. The three remaining edges cannot be replaced by a path through an intermediate course.