Nộp bài | Các bài nộp | Làm tốt nhất | Về danh sách bài |
QTREE3 - Query on a tree again! |
English | Vietnamese |
You are given a tree (an acyclic undirected connected graph) with N nodes. The tree nodes are numbered from 1 to N. In the start, the color of any node in the tree is white.
We will ask you to perfrom some instructions of the following form:
- 0 i : change the color of the i-th node (from white to black, or from black to white);
or - 1 v : ask for the id of the first black node on the path from node 1 to node v. if it doesn't exist, you may return -1 as its result.
Input
In the first line there are two integers N and Q.
In the next N-1 lines describe the edges in the tree: a line with two integers a b denotes an edge between a and b.
The next Q lines contain instructions "0 i" or "1 v" (1 ≤ i, v ≤ N).
Output
For each "1 v" operation, write one integer representing its result.
Example
Input: 9 8 1 2 1 3 2 4 2 9 5 9 7 9 8 9 6 8 1 3 0 8 1 6 1 7 0 2 1 9 0 2 1 9 Output: -1 8 -1 2 -1
Constraints & Limits
There are 12 real input files.
For 1/3 of the test cases, N=5000, Q=400000.
For 1/3 of the test cases, N=10000, Q=300000.
For 1/3 of the test cases, N=100000, Q=100000.
Được gửi lên bởi: | Fudan University Problem Setters |
Ngày: | 2008-06-14 |
Thời gian chạy: | 2s |
Giới hạn mã nguồn: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Ngôn ngữ cho phép: | Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET |
Nguồn bài: | VNOI Marathon '08 - Round 6/DivA Problem Setter: Blue Mary |
hide comments
|
|||||
2020-10-07 12:47:03
ez |
|||||
2020-06-27 13:45:35
Tham khảo: Solution: http://megaurl.in/qMPdLCYW Code: http://megaurl.in/TDxRX |
|||||
2019-09-17 02:23:30
:) |
|||||
2019-09-06 20:32:15
same ques RESULT:0 TIME: 0.00 MEM: 0k là bị s vậy mn :v.. |
|||||
2019-08-04 16:21:21
RESULT:0 TIME: 0.00 MEM: 0k là bị s vậy mn :v.. |
|||||
2018-07-29 19:09:47
Cái truy vấn cuối phải là 2 chứ nhỉ? |
|||||
2018-01-05 03:43:54
1 đấm AC :> chạy lâu v.l =)))) frostpixel aka.How 2 AC |
|||||
2017-05-17 11:47:04
hạnh phúc khi AC sau 1 buổi code :v |
|||||
2016-09-08 02:21:00
Heavy Light Decomposittion |
|||||
2016-05-24 12:18:08
HL + IT, 100 dòng :3 |