#P15534. 【MYCOI R1】那猫猫城的集市
【MYCOI R1】那猫猫城的集市
Description
Cat City has markets, connected by bidirectional roads such that any two markets can reach each other via some paths. Each market sells two types of goods ().
Now Xiao Meng, a cat, has planned journeys. Each time, Xiao Meng will start from market and travel along the shortest path to market .
When passing through a market (including and ), Xiao Meng will attempt to trade. If Xiao Meng already possesses one of the goods sold at that market, he will exchange it for the other good sold there; otherwise, he keeps his original goods.
Initially, Xiao Meng possesses a good of type . Find out what type of good Xiao Meng ends up with after the journey.
Input Format
The first line contains two positive integers .
The next two lines each contain positive integers. The -th number in the first line is , and the -th number in the second line is .
The following lines each contain two positive integers , indicating a road between market and market .
The following lines each contain three positive integers , describing a journey.
Output Format
Output lines, each containing a positive integer representing the type of good Xiao Meng finally possesses.
5 3
3 4 1 5 2
2 5 5 2 4
5 4
1 4
3 1
2 4
3 4 1
2 5 4
1 5 3
2
4
5
Hint
This problem uses bundled testing.
::cute-table{tuack} | Subtask | Constraints | Special Properties | Points | |:---------:|:---------------:|:----------------------:|:-----:| | Subtask 1 | | The tree is a chain | 5 | | Subtask 2 | | None | 15 | | Subtask 3 | | | 10 | | Subtask 4 | | The tree is a chain | 15 | | Subtask 5 | | None | 25 | | Subtask 6 | | None | 30 |
For of the data, , , .
Please pay special attention to the time and memory limits.
Explanation of Example 1

As shown in the figure, for the first query: starting from market , because Xiao Meng possesses good , he exchanges it for . At market , there is no matching good, so no exchange occurs. At market , he exchanges it for good .
A Fast I/O Template Is Provided
namespace io
{
char *p1,*p2,buf[100001];
#define getchar() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
template<typename T>
inline typename __gnu_cxx::__enable_if<__is_integer<T>::__value,T>::__type read()
{
T sum=0;
char ch;
do ch=getchar(); while(!isdigit(ch));
do sum=(sum<<1)+(sum<<3)+(ch^48),ch=getchar(); while( isdigit(ch));
return sum;
}
template<typename T>
inline typename __gnu_cxx::__enable_if<__is_integer<T>::__value,void>::__type read(T& sum)
{
sum=0;
char ch;
do ch=getchar(); while(!isdigit(ch));
do sum=(sum<<1)+(sum<<3)+(ch^48),ch=getchar(); while( isdigit(ch));
}
#undef getchar
}
Usage
int n;
long long m;
io::read(n);
io::read(m);
int k = io::read<int>();
long long q = io::read<long long>();
京公网安备 11011102002149号