L2-049 鱼与熊掌
https://pintia.cn/problem-sets/994805046380707840/exam/problems/1781658570803388424?type=7&page=1
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
vector<vector<int>> ve(n);
for(int i=0;i<n;i++){
int k;
cin>>k;
for(int j=0;j<k;j++) {
int a;
cin>>a;
ve[i].push_back(a);
}
}
int num;
cin>>num;
for(int i=0;i<num;i++){
int c,d;
int count=0;
cin>>c>>d;
for(int j=0;j<n;j++){
if(find(ve[j].begin(),ve[j].end(),c)!=ve[j].end()&&find(ve[j].begin(),ve[j].end(),d)!=ve[j].end()){
count++;
}
}
cout<<count<<endl;
}
return 0;
}