解法
漏洩した人物の情報をすべて知っていた人は怪しい。
std::includes(itr first1,itr last1,itr first2,itr last2)を使うと単純に済む。
[first1,last1]の中に[first2,last2]が全部含まれていたらtrueが返ってくる。
ソース
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ALL(a) a.begin(),a.end()
int main(){
int n;
while( cin >> n , n ){
vector < int > p[n],L;
for(int i = 0, q, d ; i < n && cin >> q ; sort(ALL(p[i])), i++ ){
while(q--) cin >> d, p[i].push_back(--d);
}
int K, l, ans = -1, flg = -1;
cin >> K;
while(K--) cin >> l, L.push_back(--l);
sort(ALL(L));
for(int i = 0 ; i < n && flg<=0 ; i++ ){
if(includes(ALL(p[i]),ALL(L))) ans = i + 1, flg++;
}
cout << (flg ? -1 : ans) << endl;
}
}
0 件のコメント:
コメントを投稿