#include <bits/stdc++.h>
using namespace std;
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#define pb push_back
#define ll long long
#define f first
#define s second
#define sz(v) int(v.size())
#define all(v) v.begin(),v.end()
int mod = 1e9 + 7;
const int N = 5000;
const ll inf = 2e18;
vector <int> g[N];
int mtr[N][N];
void solve(){
int n,k;
cin >> n >> k;
for(int i = 0; i < n; i++){
int k;
cin >> k;
for(int j = 0; j < k; j++){
int x;
cin >> x;
g[i].pb(x);
mtr[i][x] = 1;
}
}
int ans = 0;
if(k <= 3){
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(mtr[i][j] == 1 && mtr[j][i] == 1){
ans = 2;
break;
}
}
}
}
if(k == 2){
cout << ans;
return;
}
for(int i = 0; i < n; i++){
bool f = 0;
for(auto to : g[i]){
for(auto to1 : g[to]){
if(to1 == i) continue;
if(mtr[to][i] == 1 && mtr[i][to1] == 1 && mtr[to1][i] == 1 && mtr[to1][to] == 1){
f = 1;
break;
}
}
if(f == 1) break;
}
if(f == 1){
cout << 3;
return;
}
}
cout << ans;
}
signed main(){
//freopen("time.in", "r", stdin);
//freopen("time.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t1 = 1;
while(t1--){
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |