Submission #129108

# Submission time Handle Problem Language Result Execution time Memory
129108 2019-07-11T16:44:22 Z davitmarg Political Development (BOI17_politicaldevelopment) C++17
0 / 100
5 ms 1656 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<<10)+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();
        used[v]=1;
        vector<int> a,mask;
        a.PB(v);
        for(int i=0;i<g[v].size();i++)
		{
			int to=g[v][i];
			s[to]--;
			if(!used[to])
			{
				if(s[to]==k-1)
					q.push(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] || to==v)
                    mask[i]|=(1<<ind[to]);
			}

        vector<int> dp((1<<a.size())+10);
        dp[0]=1;
        for(int m=1;m<(1<<a.size());m++)
        {
            if( (((1<<f[m])^m)&(mask[f[m]])) && dp[m^(1<<f[m])])
			{
                dp[m]=1;
                ans=max(ans,c[m]);
			}
        }
	}
	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:65:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<g[v].size();i++)
                     ~^~~~~~~~~~~~
politicaldevelopment.cpp:77:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<a.size();i++)
                     ~^~~~~~~~~
politicaldevelopment.cpp:81:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<a.size();i++)
                     ~^~~~~~~~~
politicaldevelopment.cpp:82: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 Incorrect 3 ms 1528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1656 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 Incorrect 3 ms 1528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1528 KB Output isn't correct
2 Halted 0 ms 0 KB -