Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- //#include <cassert>
- using namespace std;
- typedef long long ll;
- typedef pair<int,int> pii;
- typedef pair<ll,ll> pll;
- typedef long double dbl;
- #define fi first
- #define se second
- #define sz(a) ((int)a.size())
- #define pb push_back
- const int inf_int = 1e9;
- const int MAXN = 205;
- const int MX = 1e5+10;
- int cnt[MAXN];
- bool has[MAXN];
- void solve(){
- srand(time(0));
- int n;
- cin >> n;
- cerr<<"new test "<<n<<endl;
- memset(cnt,0,sizeof cnt);
- memset(has,1,sizeof has);
- for(int i=1;i<=n;++i){
- int d;
- cin >> d;
- cerr <<"d : "<<d<<endl;
- vector<int> ex;
- for(int e=1;e<=d;++e){
- int x;
- cin >> x;
- cnt[x]++;
- if(has[x]){
- ex.pb(x);
- }
- }
- if(sz(ex)==0){
- cout <<"-1"<<endl;
- cerr <<"output "<<-1<<endl;
- } else{
- int mn = inf_int;;
- for(int v:ex){
- mn = min(mn,cnt[v]);
- }
- vector<int> spec;
- for(int v:ex){
- if(cnt[v]==mn){
- spec.pb(v);
- }
- }
- random_shuffle(spec.begin(),spec.end());
- has[spec[0]] = 0;
- cout << spec[0]<<endl;
- cerr <<"output "<<spec[0]<<endl;
- }
- }
- cout.flush();
- }
- signed main(){
- #ifdef zxc
- // freopen("input.txt","r",stdin);
- // freopen("output1.txt","w",stdout);
- #endif // zxc
- /* ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- int t = 1;
- cin >> t;
- for(int i=1;i<=t;++i){
- // cout <<"Case #"<<i<<": ";
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment