This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 5e4+10;
int n, k, gr[maxn];
vector<int> g[maxn];
set<int> stg[maxn];
vector<int> vrts,adds;
int bck(int i) {
if(i == vrts.size()) return adds.size();
int ans = bck(i+1);
int u = vrts[i];
bool ok = true;
for(auto v : adds) if(stg[u].count(v) == 0) ok = false;
if(ok) {
adds.pb(u);
ans = max(ans, bck(i+1));
adds.pop_back();
}
return ans;
}
void solve() {
cin >> n >> k;
int ans = 1;
for(int i = 0; i < n; i++) {
int d; cin >> d;
gr[i] = d;
while(d--) {
int x; cin >> x;
stg[i].insert(x);
g[i].pb(x);
}
}
set<pair<int,int>> st;
for(int i = 0; i < n; i++) {
st.insert(mp(gr[i],i));
}
while(st.size()) {
int u = st.begin()->sc;
st.erase(st.begin());
if(gr[u] >= k) {
ans = k;
break;
}
vrts.clear();
adds.pb(u);
for(auto v : stg[u]) vrts.pb(v);
ans = max(ans, bck(0));
adds.pop_back();
// bool ok = true;
// for(auto v1 : stg[u]) {
// for(auto v2 : stg[u]) {
// if(v1 != v2 && stg[v1].count(v2) == 0) ok = false;
// }
// }
// if(ok) ans = max(ans, gr[u]+1);
for(auto v : stg[u]) {
stg[v].erase(u);
st.erase(mp(gr[v],v));
--gr[v];
st.insert(mp(gr[v],v));
}
}
cout << ans << endl;
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
int tt = 1;
// cin >> tt;
while(tt--) {
solve();
}
}
Compilation message (stderr)
politicaldevelopment.cpp: In function 'long long int bck(long long int)':
politicaldevelopment.cpp:21:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if(i == vrts.size()) return adds.size();
| ~~^~~~~~~~~~~~~~
# | 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... |