洛谷 3524 [POI2011]IMP-Party

33 篇文章 0 订阅

题目描述

Byteasar intends to throw up a party.
Naturally, he would like it to be a success. Furthermore, Byteasar is quite certain that to make it so it suffices if all invited guests know each other. He is currently trying to come up with a list of his friends he would like to invite.
Byteasar has nn friends, where nn is divisible by 3.
Fortunately, most of Byteasar’s friends know one another.
Furthermore, Byteasar recalls that he once attended a party where there were \frac{2}{3}n​3
​2​​ n of his friends, and where everyone knew everyone else.
Unfortunately, Byteasar does not quite remember anything else from that party.
In particular, he has no idea which of his friends attended it.
Byteasar does not feel obliged to throw a huge party, but he would like to invite at least \frac{n}{3} of his friends.
He has no idea how to choose them, so he asks you for help.
给定一张n个点m条边的图n\equiv 0(mod\ 3)n≡0(mod 3),保证存在一个大小为\frac{2}{3}n​3​2​​ n的团,要求输出一个大小为\frac{n}{3}​3​n​​ 的团
输入输出格式
输入格式:
In the first line of the standard input two integers, nn and mm (3\le n\le 3\ 0003≤n≤3 000, \frac{\frac{2}{3}n(\frac{2}{3}n-1)}{2}\leq m\leq \frac{n(n-1)}{2}
​2
​3
​2
​​ n(
​3

​2
​​ n−1)
​​ ≤m≤
​2

​n(n−1)
​​ ), are given,separated by a single space. These denote the number of Byteasar’s friends and the number of pairs of his friends who know each other, respectively.

Byteasar’s friends are numbered from 1 to nn.

Each of the following mm lines holds two integers separated by a single space.

The numbers in line no. i+1i+1 (for i=1,2,…,mi=1,2,…,m) are a_ia
​i
​​ and b_ib
​i
​​ (1\le a_i

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>

using namespace std;
#define MAXN 4005
int Mp[MAXN][MAXN];
bool is_del[MAXN];
inline void read(int &x){
    x=0; int f=1; char c=getchar();
    while(c>'9'||c<'0'){ if(c=='-')f=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ x=x*10+c-'0'; c=getchar(); } x*=f;
}

int main(int argc,char *argv[]){
    int n,m;
    read(n),read(m);
    for(int u,v,i=1; i<=m; ++i){
        read(u),read(v);
        Mp[u][v] = Mp[v][u] = true;
    }
    for(int i=1; i<=n; ++i)
        if(!is_del[i])
            for(int j=1; j<=n; ++j)
                if(j!=i && !is_del[j] && !Mp[i][j]){
                    is_del[i] = is_del[j] = true;
                    break;
                }
    int tot=0;
    for(int i=1; i<=n; ++i){
        if(is_del[i]) continue;
        printf("%d ",i);
        if(++tot == n/3) break;
    }
    printf("\n");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七情六欲·

学生党不容易~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值