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