#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
cerr<<vars<<" = ";
string delim="";
(...,(cerr<<delim<<values,delim=", "));
cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif
#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxN=5e4+5; //make sure this is right
const int mod=1e9+7;
/*
transform the directed graph to a bidirectional graph
an edge exists between a and b iff there is an edge a->b and b->a
binary search for the best k
start from the lowest node, only traverse to greater nodes that have degree >= k-1
*/
set<int> graph[mxN];
vector<int> cur;
int n,k;
bool dfs(int &s){
if(sz(cur)==s)
return 1;
int at=cur.back();
for(int i:graph[at]){
if(i<=at || sz(graph[i])<s-1)
continue;
int bad=0;
for(int &j:cur){
if(!graph[i].count(j)){
bad=1;
break;
}
}
if(bad)
continue;
cur.pb(i);
if(dfs(s))
return 1;
cur.pop_back();
}
return 0;
}
bool check(int &s){
for(int i=0;i<n;i++){
if(sz(graph[i])<s-1)
continue;
cur={i};
if(dfs(s))
return 1;
}
return 0;
}
int main(){
cin.sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
cin>>n>>k;
for(int i=0;i<n;i++){
int d; cin>>d;
while(d--){
int x; cin>>x;
graph[i].insert(x);
}
}
for(int i=0;i<n;i++){
vector<int> rem;
for(int j:graph[i]){
if(!graph[j].count(i))
rem.pb(j);
}
for(int &j:rem)
graph[i].erase(j);
}
int l=1; int r=k;
int ans=1;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)){
ans=mid; l=mid+1;
} else{
r=mid-1;
}
}
cout<<ans<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
4 ms |
2636 KB |
Output is correct |
3 |
Correct |
6 ms |
3196 KB |
Output is correct |
4 |
Correct |
5 ms |
3148 KB |
Output is correct |
5 |
Correct |
5 ms |
3172 KB |
Output is correct |
6 |
Correct |
5 ms |
3188 KB |
Output is correct |
7 |
Correct |
4 ms |
3148 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
4 ms |
2636 KB |
Output is correct |
3 |
Correct |
6 ms |
3196 KB |
Output is correct |
4 |
Correct |
5 ms |
3148 KB |
Output is correct |
5 |
Correct |
5 ms |
3172 KB |
Output is correct |
6 |
Correct |
5 ms |
3188 KB |
Output is correct |
7 |
Correct |
4 ms |
3148 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
5 ms |
3148 KB |
Output is correct |
12 |
Correct |
5 ms |
3148 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
6 ms |
3148 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
5 ms |
3184 KB |
Output is correct |
17 |
Correct |
2 ms |
2636 KB |
Output is correct |
18 |
Correct |
5 ms |
3148 KB |
Output is correct |
19 |
Correct |
2 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2888 KB |
Output is correct |
21 |
Correct |
3 ms |
2892 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
5 ms |
3324 KB |
Output is correct |
24 |
Correct |
2 ms |
2636 KB |
Output is correct |
25 |
Correct |
5 ms |
3276 KB |
Output is correct |
26 |
Correct |
5 ms |
3148 KB |
Output is correct |
27 |
Correct |
5 ms |
3148 KB |
Output is correct |
28 |
Correct |
5 ms |
3148 KB |
Output is correct |
29 |
Correct |
6 ms |
3148 KB |
Output is correct |
30 |
Correct |
25 ms |
3364 KB |
Output is correct |
31 |
Correct |
6 ms |
3312 KB |
Output is correct |
32 |
Correct |
20 ms |
3368 KB |
Output is correct |
33 |
Correct |
6 ms |
3316 KB |
Output is correct |
34 |
Correct |
6 ms |
3336 KB |
Output is correct |
35 |
Correct |
5 ms |
2936 KB |
Output is correct |
36 |
Correct |
4 ms |
2892 KB |
Output is correct |
37 |
Correct |
4 ms |
2892 KB |
Output is correct |
38 |
Correct |
4 ms |
2816 KB |
Output is correct |
39 |
Correct |
4 ms |
2892 KB |
Output is correct |
40 |
Correct |
7 ms |
3660 KB |
Output is correct |
41 |
Correct |
4 ms |
2808 KB |
Output is correct |
42 |
Correct |
7 ms |
3704 KB |
Output is correct |
43 |
Correct |
7 ms |
3700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2816 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
465 ms |
26440 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
334 ms |
26384 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
497 ms |
26428 KB |
Output is correct |
16 |
Correct |
341 ms |
26428 KB |
Output is correct |
17 |
Correct |
468 ms |
26524 KB |
Output is correct |
18 |
Correct |
458 ms |
26428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
4 ms |
2636 KB |
Output is correct |
3 |
Correct |
6 ms |
3196 KB |
Output is correct |
4 |
Correct |
5 ms |
3148 KB |
Output is correct |
5 |
Correct |
5 ms |
3172 KB |
Output is correct |
6 |
Correct |
5 ms |
3188 KB |
Output is correct |
7 |
Correct |
4 ms |
3148 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
5 ms |
3148 KB |
Output is correct |
12 |
Correct |
5 ms |
3148 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
6 ms |
3148 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
5 ms |
3184 KB |
Output is correct |
17 |
Correct |
2 ms |
2636 KB |
Output is correct |
18 |
Correct |
5 ms |
3148 KB |
Output is correct |
19 |
Correct |
2 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2888 KB |
Output is correct |
21 |
Correct |
3 ms |
2892 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
5 ms |
3324 KB |
Output is correct |
24 |
Correct |
2 ms |
2636 KB |
Output is correct |
25 |
Correct |
5 ms |
3276 KB |
Output is correct |
26 |
Correct |
5 ms |
3148 KB |
Output is correct |
27 |
Correct |
5 ms |
3148 KB |
Output is correct |
28 |
Correct |
5 ms |
3148 KB |
Output is correct |
29 |
Correct |
6 ms |
3148 KB |
Output is correct |
30 |
Correct |
25 ms |
3364 KB |
Output is correct |
31 |
Correct |
6 ms |
3312 KB |
Output is correct |
32 |
Correct |
20 ms |
3368 KB |
Output is correct |
33 |
Correct |
6 ms |
3316 KB |
Output is correct |
34 |
Correct |
6 ms |
3336 KB |
Output is correct |
35 |
Correct |
5 ms |
2936 KB |
Output is correct |
36 |
Correct |
4 ms |
2892 KB |
Output is correct |
37 |
Correct |
4 ms |
2892 KB |
Output is correct |
38 |
Correct |
4 ms |
2816 KB |
Output is correct |
39 |
Correct |
4 ms |
2892 KB |
Output is correct |
40 |
Correct |
7 ms |
3660 KB |
Output is correct |
41 |
Correct |
4 ms |
2808 KB |
Output is correct |
42 |
Correct |
7 ms |
3704 KB |
Output is correct |
43 |
Correct |
7 ms |
3700 KB |
Output is correct |
44 |
Correct |
12 ms |
4684 KB |
Output is correct |
45 |
Correct |
2 ms |
2636 KB |
Output is correct |
46 |
Correct |
7 ms |
3660 KB |
Output is correct |
47 |
Correct |
22 ms |
4740 KB |
Output is correct |
48 |
Correct |
9 ms |
3696 KB |
Output is correct |
49 |
Correct |
21 ms |
4684 KB |
Output is correct |
50 |
Correct |
25 ms |
4708 KB |
Output is correct |
51 |
Correct |
30 ms |
6808 KB |
Output is correct |
52 |
Correct |
6 ms |
3192 KB |
Output is correct |
53 |
Execution timed out |
3068 ms |
7264 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
4 ms |
2636 KB |
Output is correct |
3 |
Correct |
6 ms |
3196 KB |
Output is correct |
4 |
Correct |
5 ms |
3148 KB |
Output is correct |
5 |
Correct |
5 ms |
3172 KB |
Output is correct |
6 |
Correct |
5 ms |
3188 KB |
Output is correct |
7 |
Correct |
4 ms |
3148 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
5 ms |
3148 KB |
Output is correct |
12 |
Correct |
5 ms |
3148 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
6 ms |
3148 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
5 ms |
3184 KB |
Output is correct |
17 |
Correct |
2 ms |
2636 KB |
Output is correct |
18 |
Correct |
5 ms |
3148 KB |
Output is correct |
19 |
Correct |
2 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2888 KB |
Output is correct |
21 |
Correct |
3 ms |
2892 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
5 ms |
3324 KB |
Output is correct |
24 |
Correct |
2 ms |
2636 KB |
Output is correct |
25 |
Correct |
5 ms |
3276 KB |
Output is correct |
26 |
Correct |
5 ms |
3148 KB |
Output is correct |
27 |
Correct |
5 ms |
3148 KB |
Output is correct |
28 |
Correct |
5 ms |
3148 KB |
Output is correct |
29 |
Correct |
6 ms |
3148 KB |
Output is correct |
30 |
Correct |
25 ms |
3364 KB |
Output is correct |
31 |
Correct |
6 ms |
3312 KB |
Output is correct |
32 |
Correct |
20 ms |
3368 KB |
Output is correct |
33 |
Correct |
6 ms |
3316 KB |
Output is correct |
34 |
Correct |
6 ms |
3336 KB |
Output is correct |
35 |
Correct |
5 ms |
2936 KB |
Output is correct |
36 |
Correct |
4 ms |
2892 KB |
Output is correct |
37 |
Correct |
4 ms |
2892 KB |
Output is correct |
38 |
Correct |
4 ms |
2816 KB |
Output is correct |
39 |
Correct |
4 ms |
2892 KB |
Output is correct |
40 |
Correct |
7 ms |
3660 KB |
Output is correct |
41 |
Correct |
4 ms |
2808 KB |
Output is correct |
42 |
Correct |
7 ms |
3704 KB |
Output is correct |
43 |
Correct |
7 ms |
3700 KB |
Output is correct |
44 |
Correct |
2 ms |
2636 KB |
Output is correct |
45 |
Correct |
157 ms |
18532 KB |
Output is correct |
46 |
Correct |
67 ms |
10532 KB |
Output is correct |
47 |
Correct |
198 ms |
18604 KB |
Output is correct |
48 |
Correct |
117 ms |
18440 KB |
Output is correct |
49 |
Correct |
37 ms |
7916 KB |
Output is correct |
50 |
Execution timed out |
3052 ms |
23768 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |