PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000060. Phụ thuộc tệp nguồn (Import Spaghetti)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Phụ thuộc tệp nguồn (Import Spaghetti)
Import Spaghetti
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Some source files import other files, forming a directed dependency graph. Find a directed cycle with the fewest edges and print its file names in cyclic order without repeating its first name. A self-import is a cycle of length one.
Input
First n m; then n distinct file names; then m directed dependencies sourceFile importedFile.
Output
Print exactly SHIP IT if acyclic; otherwise print any shortest directed cycle as space-separated file names, without repeating the first name.
Subtasks
- Subtask 1 (40 points): . File names are distinct alphanumeric tokens. Each ordered import edge appears at most once; a file may import itself.
- Subtask 2 (60 points): . File names are distinct alphanumeric tokens. Each ordered import edge appears at most once; a file may import itself.
Examples
Input
3 3
a b c
a b
b c
c a
Output
a b c
Explanation
Dependencies a→b→c→a form a three-file cycle. No shorter cycle exists; any rotation of a b c is accepted.