[POI2011]IMP-Party

Summary

The meaning of problems: None of the n points m edges to FIG \ (n \ equiv 0 (\ BMOD. 3) \) , to ensure that there is a size \ (\ frac {2} { 3} n \) groups, requirements an output size \ (\ frac {1} { 3} n \) regiment. \ (n-\ Leq 3000 \) .

This question is to find special is that group, but it has to ensure a \ (\ frac {2} { 3} n \) the size of the group, but only allows us to find a \ (\ frac {1} { 3} n \) of the group. this means that we can give up some points in the process of looking.

Groups of two adjacent points are, so we do not judge directly enumerate two points adjacent to and directly give it. Each point is give it up to a consideration of the correctness of doing this. You find two point must not be both \ (n \ \ frac {2 } {3}) points in the group, or is a group in which a dot is not, or is not one of the two points. this operation is therefore performed up \ ( \ frac {1} {3} n \) times, each taking two points, the last remaining \ (\ frac {1} { 3} \) points must be a group.

#include<bits/stdc++.h>
using namespace std;
const int N=3e3+5;

int n,m,e[N][N];
bool v[N];

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        e[u][v]=e[v][u]=1;
    }
    for(int i=1;i<=n;i++){
        if(v[i])continue;
        for(int j=i+1;j<=n;j++)if(!v[j]&&!e[i][j]){
            v[j]=v[i]=1;break;
        }
    }
    int tot=0;
    for(int i=1;i<=n;i++){
        if(!v[i])cout<<i<<' ',++tot;
        if(tot*3==n)break;
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/sshwy/p/11026360.html