题目链接
题意
某君有n朋友,他需要和她们玩耍m天,每一天都有一些人可以和他玩,某君每天只能选择和一个人玩,如果和一个人玩超过m/2上取整次,就会不高兴,问是否有不会不高兴的选择方案,有的话输出方案
思路
裸的最大流,建立s,t,日期点,朋友点。s向所有日期连边,权1,对于每一天,将日期点向当天可以游戏的朋友连边,权1,所有朋友点向t连边,权为m/2上取整。
跑最大流,如果maxflow和日期数相等,那么就是有方案。至于输出方案,我们跑完dinic后,日期和朋友间连的正向边如果权变成了0,说明这个日期选的是这个朋友,输出即可。
教训/收获
为什么DIV2的C题会有网络流?
代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
//#define int long long
//#define double long double
using namespace std;
typedef long long ll;
const int maxn=200505;
const int maxe=800050;
const int inf=0x3f3f3f3f;
int n,m,k;
int head[maxn],cnt;
struct Edge{
int v;
int w;
int next;
}edge[maxe];
int deep[maxn];
int now[maxe];
void init(){
memset(head,-1,sizeof(head));
cnt=