답안 #310622

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
310622 2020-10-07T14:04:21 Z MrDomino Political Development (BOI17_politicaldevelopment) C++14
0 / 100
939 ms 524292 KB
#include <bits/stdc++.h>

using namespace std;

const int N=50000+7;
int n;
int k;
int sol;
vector<int> g[N];
set<pair<int,int>> s;

void del(int x)
{
        for (auto &i : g[x])
        {
                vector<int> gnew_i;
                for (auto &y : g[i])
                {
                        if (y!=x)
                                gnew_i.push_back(y);
                }
                s.erase({(int) g[i].size(),i});
                s.insert({(int) g[i].size()-1,i});
                g[i]=gnew_i;
        }
        g[x].clear();
}

vector<int> operator & (vector<int> a, vector<int> b)
{
        vector<int> c;
        int i=0,j=0;
        while (i<(int) a.size()&&j<(int) b.size())
        {
                if (a[i]<b[j])
                {
                        i++;
                        continue;
                }
                if (b[j]<a[i])
                {
                        j++;
                        continue;
                }
                c.push_back(a[i]);
                i++;
                j++;
        }
        return c;
}

vector<int> nodes;
vector<int> good;

void bkt()
{
        if ((int) good.size()+(int)nodes.size()<=sol)
                return;
        if ((int)nodes.size()>sol)
                sol=(int)nodes.size();
        for (auto &x : good)
        {
                vector<int> init=good;
                good=good&g[x];
                nodes.push_back(x);
                bkt();
                nodes.pop_back();
                good=init;
        }
}

int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);

        cin>>n;
        for (int i=0;i<n;i++)
        {
                int l;
                cin>>l;
                for (int j=1;j<=l;j++)
                {
                        int x;
                        cin>>x;
                        g[i].push_back(x);
                }
                sort(g[i].begin(),g[i].end());
                s.insert({(int)g[i].size(),i});
        }
        while (!s.empty())
        {
                auto it=*s.begin();
                s.erase(it);
                int node=it.second;
                good=g[node];
                nodes={node};
                bkt();
                del(node);
        }
        cout<<sol<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Runtime error 939 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Runtime error 939 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 871 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Runtime error 939 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Runtime error 939 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -