Submission #520694

#TimeUsernameProblemLanguageResultExecution timeMemory
520694Yazan_AlattarPolitical Development (BOI17_politicaldevelopment)C++14
100 / 100
1681 ms42640 KiB
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
#include <assert.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 200007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

queue <int> q;
vector <int> adj[M];
set <int> edge[M];
int n, k, sz[M], ans;
bool vist[M];

bool cmp(int x, int y) { return adj[x].size() < adj[y].size(); }

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        int m;
        cin >> m;
        for(int j = 1; j <= m; ++j){
            int x; cin >> x;
            adj[i].pb(x + 1);
            edge[i].insert(x + 1);
        }
        if(m < k) q.push(i);
        sz[i] = m;
    }
    while(!q.empty()){
        int node = q.front();
        q.pop();
        vector <int> v;
        for(auto j : adj[node]) if(!vist[j]) v.pb(j);
        for(int mask = 0; mask < (1 << v.size()); ++mask){
            vector <int> clique; clique.pb(node);
            for(int i = 0; i < v.size(); ++i) if((mask >> i) & 1) clique.pb(v[i]);
            if(clique.size() <= ans) continue;
            bool ok = 1;
            for(int i = 0; i < clique.size(); ++i)
                for(int j = i + 1; j < clique.size(); ++j)
                    ok &= edge[clique[i]].count(clique[j]);
            if(ok) ans = clique.size();
        }
        for(auto i : adj[node]){
            --sz[i];
            if(sz[i] == k - 1) q.push(i);
        }
        vist[node] = 1;
    }
    cout << ans << endl;
    return 0;
}

Compilation message (stderr)

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:57:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             for(int i = 0; i < v.size(); ++i) if((mask >> i) & 1) clique.pb(v[i]);
      |                            ~~^~~~~~~~~~
politicaldevelopment.cpp:58:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |             if(clique.size() <= ans) continue;
      |                ~~~~~~~~~~~~~~^~~~~~
politicaldevelopment.cpp:60:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |             for(int i = 0; i < clique.size(); ++i)
      |                            ~~^~~~~~~~~~~~~~~
politicaldevelopment.cpp:61:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |                 for(int j = i + 1; j < clique.size(); ++j)
      |                                    ~~^~~~~~~~~~~~~~~
#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...