Bananas are the favoured food of monkeys.
In the forest, there is a Banana Company that provides bananas from different places.
The company has two lists.
The first list records the types of bananas preferred by different monkeys, and the second one records the types of bananas from different places.
Now, the supplier wants to know, whether a monkey can accept at least one type of bananas from a place.
Remenber that, there could be more than one types of bananas from a place, and there also could be more than one types of bananas of a monkey’s preference.
Input Format
The first line contains an integer TT, indicating that there are TT test cases.
For each test case, the first line contains two integers NN and MM, representing the length of the first and the second lists respectively.
In the each line of following NN lines, two positive integers i, ji,j indicate that the ii-th monkey favours the jj-th type of banana.
In the each line of following MM lines, two positive integers j, kj,k indicate that the jj-th type of banana could be find in the kk-th place.
All integers of the input are less than or equal to 5050.
Output Format
For each test case, output all the pairs x, yx,y that the xx-the monkey can accept at least one type of bananas from the yy-th place.
These pairs should be outputted as ascending order. That is say that a pair of x, yx,y which owns a smaller xx should be output first.
If two pairs own the same xx, output the one who has a smaller yy first.
And there should be an empty line after each test case.
样例输入
1
6 4
1 1
1 2
2 1
2 3
3 3
4 1
1 1
1 3
2 2
3 3
样例输出
1 1
1 2
1 3
2 1
2 3
3 3
4 1
4 3
签到题
题意就是 给出 一个 n 和m
下面有n行 加m行
前n行 每行输入2个数 i j 代表了第i个猴子 喜欢第j种 香蕉
后m行 每行输入2个数j k 代表第j个香蕉 在 第k个区域
题目让输出 有哪些猴子 在哪些 局域中 至少喜欢一种香蕉
按照 猴子的序号从小到大 排列 , 如果序号相同按照 区域序号从小到达排列
code:
#include
#include
#include
#include
using namespace std;
struct node
{
int x;
int y;
} shu[51];
int cmp(node xx, node yy)
{
if (xx.x==yy.x)
return xx.yelse
return xx.xint main()
{
int N;
scanf("%d",&N);
while (N--)
{
int num=0;
vector<int>data1[51];
vector<int>data2[51];
int tt=0;
int n, m;
scanf("%d%d",&n,&m);
int i;
for (i=1; i<=n; i++)
{
int I, j=1;
scanf("%d%d",&I,&j);
data1[I].push_back(j);
if (I>num)
num = I;
}
for (i=1; i<=m; i++)
{
int j, k;
scanf("%d%d",&j,&k);
data2[j].push_back(k);
}
for (i=1; i<=num; i++)
{
if(data1[i].size()!=0)
{
for(int j=0; jint t=data1[i][j];
for(int k=0; kfor (i=0;i1; i++)
{
if (shu[i].x==shu[i+1].x&&shu[i].y==shu[i+1].y)
shu[i].x = 0;
}
for (i=0; iif (shu[i].x)
cout<" "<cout<return 0;
}