Untitled
unknown
plain_text
2 years ago
941 B
8
Indexable
#pragma GCC optimize("O2,no-stack-protector,unroll-loops")
#define ll long long
#define pb push_back
#define ipar(arr, n) vector<ll> arr(n); for(int i=0;i<n;i++) cin>>arr[i];
#include <cmath>
#include <bits/stdc++.h>
#define pii pair<int, int>;
#define pll pair<ll, ll>;
using namespace std;
void flush_map(unordered_map<ll,ll>&ls){
for(auto i:ls) cout<<i.first<<"-"<<i.second<<" ";
cout<<"\n";
}
void solve(){
ll n,m,l;cin>>n>>m>>l;
unordered_map<ll,ll>ls;
ll ind=0;
while(m--){
ll len;cin>>len;
while(len--){
ll x;cin>>x;
ls[x]=ind; //color id belongs to list ind
}
ind++;
}
//flush_map(ls);
ipar(strip,l);
ll res=1;
for(ll i=1;i<l;i++){
if(ls[strip[i]]!=ls[strip[i-1]]) res++;
}
cout<<res<<"\n";
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--) solve();
}
Editor is loading...
Leave a Comment