Submission #129119

# Submission time Handle Problem Language Result Execution time Memory
129119 2019-07-11T17:15:41 Z davitmarg Political Development (BOI17_politicaldevelopment) C++17
0 / 100
7 ms 1784 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <bitset>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;

int n,k,used[50004],c[50004],ind[50004],s[50004],f[(1<<11)+5],ans=1;
vector<int> g[50004];
queue<int> q;

int main()
{
	cin>>n>>k;
    for(int i=0;i<n;i++)
	{
        int d,to;
        cin>>d;
        while(d--)
		{
            scanf("%d",&to);
            g[i].PB(to);
		}
		s[i]=g[i].size();
	}

    for(int i=1;i<(1<<k);i++)
	{
        for(int j=k-1;j>=0;j--)
			if((i&(1<<j)))
			{
				f[i]=j;
                c[i]++;
			}
	}

    for(int i=0;i<n;i++)
        if(s[i]<=k)
            q.push(i);

    while(!q.empty())
	{
        int v=q.front();
        q.pop();
        if(used[v])
			continue;
        used[v]=1;
        vector<int> a,mask;
        for(int i=0;i<g[v].size();i++)
		{
			int to=g[v][i];
			s[to]--;
			if(s[to] <= k)
				q.push(to);
			if(!used[to])
			{
				a.PB(to);
			}
		}

        for(int i=0;i<a.size();i++)
            ind[a[i]]=i;

        mask.resize(a.size());
        for(int i=0;i<a.size();i++)
            for(int j=0;j<g[a[i]].size();j++)
			{
				int to=g[a[i]][j];
                if(!used[to])
                    mask[i]|=(1<<ind[to]);
			}

        vector<int> dp((1<<k)+10);
        dp[0]=1;
        for(int m=1;m<(1<<a.size());m++)
        {
            if((((1<<f[m])^m)&(mask[f[m]]))==((1<<f[m])^m) && dp[m^(1<<f[m])])
			{
                dp[m]=1;
                ans=max(ans,c[m]+1);
			}
        }
	}
	cout<<ans<<endl;
	return 0;
}


/*

5 4
4 1 2 3 4
3 0 2 3
3 0 1 3
3 0 1 2
1 0

*/

Compilation message

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:66:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<g[v].size();i++)
                     ~^~~~~~~~~~~~
politicaldevelopment.cpp:78:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<a.size();i++)
                     ~^~~~~~~~~
politicaldevelopment.cpp:82:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<a.size();i++)
                     ~^~~~~~~~~
politicaldevelopment.cpp:83:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=0;j<g[a[i]].size();j++)
                         ~^~~~~~~~~~~~~~~
politicaldevelopment.cpp:38:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&to);
             ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 3 ms 1528 KB Output is correct
3 Incorrect 7 ms 1784 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 3 ms 1528 KB Output is correct
3 Incorrect 7 ms 1784 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1528 KB Output is correct
2 Incorrect 3 ms 1528 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 3 ms 1528 KB Output is correct
3 Incorrect 7 ms 1784 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 3 ms 1528 KB Output is correct
3 Incorrect 7 ms 1784 KB Output isn't correct
4 Halted 0 ms 0 KB -