# Codeforces Round #709_C. Basic Diplomacy

C. Basic Diplomacy

题目链接在此!

题面:

在这里插入图片描述
在这里插入图片描述

中文题意

m 天每天都要找一个人玩。
每个人不能被选取超过m/2次。
给定每天能够选取的人数,问安排。

思路

把时间按照朋友多少升序排序,优先先安排人数少的日子。

代码:

//题意 求经过特定3点的最小生成树
//思路:枚举任何一点作为支撑点 ,特定的3点要相连必须经过共同的一点 ,求这三点到所枚举点的最短路和,取最小值即为答案
#include<iostream>
#include<stdio.h>
#include<string.h>
#include <random>
#include<queue>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
const int maxn = 114514;
using namespace std;


struct Node {
    int day, endd;
    vector<int> v;

    bool operator<(const Node &a) const {
        return v.size() < a.v.size();
    }
} node[maxn];

bool cmp(Node &a, Node &b) {
    return a.v.size() < b.v.size();
}

map<int, int> mp;
int oyxbh[maxn];

int main() {
    int n, m;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while (T--) {
        cin >> n >> m;
        mp.clear();
        for (int i = 1; i <= m; ++i) {
            node[i].day = i;
        }
        for (int i = 1; i <= m; ++i) {
            node[i].v.clear();
            cin >> node[i].endd;
            for (int j = 1; j <= node[i].endd; ++j) {
                int temp;
                cin >> temp;
                node[i].v.push_back(temp);
            }
        }
        sort(node + 1, node + m + 1);
        bool flag = 0;
        for (int i = 1; i <= m; ++i) {
            int tempp;
            int tmp = (m + 1) / 2;
            for (tempp = 0; tempp < node[i].endd; ++tempp) {
                if (mp[node[i].v[tempp]] < tmp) {
                    mp[node[i].v[tempp]]++;
                    oyxbh[node[i].day] = node[i].v[tempp];
                    break;
                }
                if (node[i].v[tempp] > n) continue;

            }
            if (tempp == node[i].endd) {
                flag = 1;
                break;
            }
        }
        if (!flag) {
            cout << "YES" << endl;
            cout << oyxbh[1];
            for (int i = 2; i <= m; ++i) cout << " " << oyxbh[i];
            cout << endl;
        } else cout << "NO" << endl;
    }
    
}


//OK
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值