# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
244693 | TheLorax | Political Development (BOI17_politicaldevelopment) | C++11 | 3078 ms | 1024 KiB |
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>
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")
#define F first
#define S second
#define MT make_tuple
#define MP make_pair
#define SZ(a) ((int)(a).size())
#define PB push_back
#define LEFT(i) (2*(i))
#define RIGHT(i) (2*(i)+1)
#define PAR(i) ((i)/2)
#define ALL(a) (a).begin(), (a).end()
#define END(s) {cout << s;return;}
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
int n;
std::vector<std::vector<int> > e;
void rek(std::vector<int> &ou, int k, int ki=0){
if(ki==k){
printf("%d\n", k);
exit(0);
}
for(int i=0; i<n; i++)
if(ou[i]==ki){
for(int x: e[i])
ou[x]++;
rek(ou, k, ki+1);
for(int x: e[i])
ou[x]--;
}
return;
}
void trycli(int k){
std::vector<int> ou(n);
set<ii> s;
for(int i=0; i<n; i++){
int d=SZ(e[i]);
s.insert({d,i});
ou[i]=d;
}
auto x=s.begin();
while (x!=s.end() && x->F<k-1) {
ou[x->S]=-1;
for(auto y: e[x->S]){
if(ou[y]<0)
continue;
s.erase({ou[y], y});
ou[y]--;
s.erase({ou[y], y});
}
x=s.begin();
}
if(x==s.end())
return;
if(SZ(s)==k){
printf("%d\n", k);
exit(0);
}
for(int i=0; i<n; i++){
if(ou[i]>=0)
ou[i]=0;
else
ou[i]=INT_MIN/2;
}
rek(ou, k);
}
int main(){
int k;
scanf("%d %d", &n, &k);
e.resize(n);
for(int i=0; i<n; i++){
int d; scanf("%d", &d);
e[i].resize(d);
for(int j=0; j<d; j++)
scanf("%d", &e[i][j]);
}
for(int i=k; i>1; i--)
trycli(i);
}
Compilation message (stderr)
# | 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... |