Submission #944276

#TimeUsernameProblemLanguageResultExecution timeMemory
944276idasPolitical Development (BOI17_politicaldevelopment)C++11
16 / 100
2382 ms524288 KiB
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) ((int)((x).size()))
#define le(vec) vec[vec.size()-1]
#define all(x) (x).begin(), (x).end()
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;

const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;

void setIO()
{
    FAST_IO;
}

void setIO(string s)
{
    FAST_IO;
    freopen((s+".in").c_str(), "r", stdin);
    freopen((s+".out").c_str(), "w", stdout);
}

const int N=5e4+10;
int n, k, d[N];
vi ad[N];
bool v[N];

bool three=false;
void dfs(int u, int prv=-1)
{
    v[u]=true;
    for(auto it : ad[u]){
        if(!v[it]){
            d[it]=d[u]+1;
            dfs(it, u);
        }
        else if(it!=prv && d[it]!=-1 && d[u]-d[it]==2){
            three=true;
        }
    }
    d[u]=-1;
}

map<vi, int> cn;
vi now;
int ans;
void rec(vi &ar, int in=-1, int siz=0)
{
    if(in!=-1){
        now.pb(ar[in]);
        cn[now]++;
        if(cn[now]>=siz){
            ans=max(ans, siz);
        }
    }
    FOR(i, in+1, sz(ar))
    {
        rec(ar, i, siz+1);
    }
    if(!now.empty()) now.pop_back();
}

int main()
{
    setIO();
    cin >> n >> k;
    bool all=true;
    vi inf[n];
    FOR(i, 0, n)
    {
        int x; cin >> x;
        if(x!=0){
            all=false;
        }

        inf[i].pb(i);
        FOR(j, 0, x)
        {
            int u; cin >> u;
            ad[i].pb(u);
            inf[i].pb(u);
        }

        sort(all(inf[i]));
    }

    if(k<=3){
        FOR(i, 0, n)
        {
            if(!v[i]){
                d[i]=0;
                dfs(i);
            }
        }

        if(three){
            cout << 3 << '\n';
        }
        else if(!all){
            cout << 2 << '\n';
        }
        else{
            cout << 1 << '\n';
        }
    }
    else{
        FOR(i, 0, n)
        {
            rec(inf[i]);
        }
        cout << ans;
    }
}

Compilation message (stderr)

politicaldevelopment.cpp: In function 'void setIO(std::string)':
politicaldevelopment.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
politicaldevelopment.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...