PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000123. Truy vấn hành trình đúng số bước (Fixed Length Walk Queries)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Truy vấn hành trình đúng số bước (Fixed Length Walk Queries)
Fixed Length Walk Queries
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
Given a connected, simple, undirected graph with at least two nodes, each turn traverses one edge. For every query determine if a walk starting at can end at after exactly edge traversals. Revisiting edges or nodes is allowed. Parity matters.
Input
First line , then undirected edges , and lines . Nodes are -indexed.
Output
Print YES or NO per query.
Subtasks
-
Subtask 1 (40 points): , , , . All input conditions remain in force.
-
Subtask 2 (60 points): , , , . All input conditions remain in force.
Examples
Input
4 5 6
1 2
2 3
1 3
2 4
3 4
1 2 2
1 4 1
1 4 5
2 2 1
2 2 2
3 4 8
Output
YES
NO
YES
NO
YES
YES
Explanation
The first query has walk 1->3->2 of length 2; there is no one-step edge 1->4; round trips add two steps.