#P5838. [USACO19DEC] Milk Visits G
[USACO19DEC] Milk Visits G
Description
Farmer John plans to build farms and connect them with roads to form a tree (that is, every pair of farms is reachable, and there are no cycles). Each farm has one cow, with breed , an integer between and .
Farmer John has friends who often come to visit him. When friend visits, Farmer John and this friend will walk along the unique path from farm to farm (it is possible that ). In addition, they can taste the milk of any cow on the path they travel. Since most of Farmer John’s friends are also farmers, they have strong preferences for milk. Each friend only drinks milk from one specific breed of cow. A friend will be happy only if, during their visit, they can drink milk of their preferred breed.
Please determine whether each friend will be happy after the visit.
Input Format
The first line contains two integers and .
The second line contains space-separated integers . The cow breed on farm is given by .
The next lines each contain two distinct integers and (), indicating there is an edge between farms and .
The next lines each contain integers , , and . and are the endpoints of the path friend walks during the visit, and () is the cow breed whose milk this friend likes.
Output Format
Output a binary string of length . If friend will be happy, the -th character of the string is 1, otherwise it is 0.
5 5
1 1 2 1 2
1 2
2 3
2 4
1 5
1 4 1
1 4 2
1 3 2
1 3 1
5 5 1
10110
6 4
1 2 3 3 3 3
1 2
2 3
3 4
2 5
5 6
4 6 1
4 6 2
4 6 3
4 6 4
0110
Hint
Test point properties.
Test point is the second sample below.
Test point satisfies , .
Test points satisfy .
For of the testdata, , .
Problem author: Spencer Compton.
Translated by ChatGPT 5
京公网安备 11011102002149号