看英文题真是麻烦...理解题意花的时间比想的时间还长...裸的网络流, 我们只要限制每个人出发流量为1, 每个大学进入的流量至多为2即可, 相当于构造可行解.

----------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
 
using namespace std;
 
const int MAXN = 209;
const int MAXV = 700;
 
inline int read() {
char c = getchar();
int ret = 0;
for(; !isdigit(c); c = getchar());
for(; isdigit(c); c = getchar()) ret = ret * 10 + c - '0';
return ret;
}
 
int N, M, V, S, T;
int ans[MAXN][2], c[MAXN];
int h[MAXV], cnt[MAXV];
 
struct edge {
int to, cap;
edge *next, *rev;
} E[100000], *pt = E, *head[MAXV], *p[MAXV], *cur[MAXV];
 
inline void Add(int u, int v, int w) {
pt->to = v; pt->cap = w; pt->next = head[u]; head[u] = pt++;
}
 
inline void AddEdge(int u, int v, int w) {
Add(u, v, w); Add(v, u, 0);
head[u]->rev = head[v];
head[v]->rev = head[u];
}
 
int maxFlow() {
for(int i = 0; i < V; i++) cur[i] = head[i];
memset(cnt, 0, sizeof cnt);
memset(h, 0, sizeof h);
cnt[0] = V;
edge* e;
int Flow = 0;
for(int A = MAXV, x = S; h[S] < V; ) {
for(e = head[x]; e; e = e->next)
if(e->cap && h[e->to] + 1 == h[x]) break;
if(e) {
A = min(e->cap, A);
p[e->to] = cur[x] = e;
if((x = e->to) == T) {
Flow += A;
for(; x != S; x = p[x]->rev->to) {
p[x]->cap -= A;
p[x]->rev->cap += A;
}
A = MAXV;
}
} else {
if(!--cnt[h[x]]) break;
h[x] = V;
for(e = head[x]; e; e = e->next) if(h[e->to] + 1 < h[x] && e->cap) {
h[x] = h[e->to] + 1;
cur[x] = e;
}
cnt[h[x]]++;
if(x != S) x = p[x]->rev->to;
}
}
return Flow;
}
 
void Init() {
N = read(); M = read(); V = N + M;
for(int i = 0; i < N; i++)
for(int t = read(); t--; ) AddEdge(i, read() + N - 1, 1);
S = V++; T = V++;
for(int i = 0; i < N; i++) AddEdge(S, i, 1);
for(int i = 0; i < M; i++) AddEdge(i + N, T, 2);
}
 
int main() {
Init();
if(maxFlow() == M * 2) {
puts("YES");
for(int x = 0; x < N; x++)
for(edge* e = head[x]; e; e = e->next)
if(!e->cap) ans[e->to - N][c[e->to - N]++] = x;
for(int x = 0; x < M; x++)
printf("2 %d %d\n", ++ans[x][0], ++ans[x][1]);
} else
puts("NO");
return 0;
}

----------------------------------------------------------------------------------

242. Student's Morning

time limit per test: 0.25 sec.
memory limit per test: 6144 KB
input: standard
output: standard

One Monday morning after some very fun party N students woke up at the flat of one of them. Notice that it was a Monday morning and every student of that party needs to be in his university this day. But nobody wants to go to his university alone (there were students from different universities). So, they decided to select from all universities only K of them to visit. Every selected university must be visited by at least two of the students. Every student has his own preference list of universities. It means, if some university is in list of some student's preferred universities, this student can go to this university with some non-empty company of students. Notice, that some of students can stay at the flat and continue drinking "juices" and playing "games". For example, student Shokman was to stay home (due to failed exam) with foreign student Chokman, who remained home because of runny nose. 
In that problem there are no preferences between students, because if they have very fun party that already means that everyone of them prefers anybody from this company.

More formally, your task is, given numbers of students, selected universities and preference list of every student, to decide whether it is possible to visit all universities by at least two of students or no, and if it is possible you must output for each university numbers of students, which have to go to it in one company. One student can't be in more than one company.

Input
First line of input file contains two numbers N and K (0<=K<=N<=200). Next N lines contain preference lists of each student. Every preference list is started by number of preferred universities followed by numbers of these universities.
Output
First line of output file must contain word "YES" (without quotes), if it possible to visit all universities, satisfying rules of that task or word "NO" (also without quotes) when it is impossible. In case of positive answer next K lines must contain lists of students, who are going to corresponding university. First number in list of students must be a number of students in the list, followed by numbers of these students.
Sample test(s)
Input

Test #1 
4 2 
1 1 
2 1 2 
1 2 
2 1 2

Test #2 
3 2 
2 1 2 
2 1 2 
2 1 2

Output

Test #1 
YES 
2 1 2 
2 3 4

Test #2 
NO


Author: Alexey Preobrajensky
Resource: ---
Date: October, 2003

SGU 242. Student's Morning( 网络流 )的更多相关文章

  1. SGU 242 Student&#39;s Morning 网络流(水

    题目链接:contest=0&problem=242">点击打开链接 题意: 给定n个人,m个终点 以下n行表示每一个人能够去m个点. 每一个人仅仅能去一个点. 输出随意一个方 ...

  2. sgu 185 最短路建网络流

    题目:给出一个图,从图中找出两条最短路,使得边不重复. 分析:既然是最短路,那么,两条路径上的所有节点的入边(s,x).出边(x,e)必定是最优的,即 dis[x] = dis[s]+edge_dis ...

  3. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  4. appium日志

    2020-10-02 00:44:10:672 [Appium] Welcome to Appium v1.16.0 2020-10-02 00:44:10:673 [Appium] Non-defa ...

  5. SGU 185 Two shortest ★(最短路+网络流)

    [题意]给出一个图,求 1 -> n的2条 没有重边的最短路. 真◆神题--卡内存卡得我一脸血= =-- [思路] 一开始我的想法是两遍Dijkstra做一次删一次边不就行了么你们还又Dijks ...

  6. SGU 438 The Glorious Karlutka River =) ★(动态+分层网络流)

    [题意]有一条东西向流淌的河,宽为W,河中有N块石头,每块石头的坐标(Xi, Yi)和最大承受人数Ci已知.现在有M个游客在河的南岸,他们想穿越这条河流,但是每个人每次最远只能跳D米,每跳一次耗时1秒 ...

  7. SGU 326 Perspective ★(网络流经典构图の竞赛问题)

    [题意]有n(<=20)只队伍比赛, 队伍i初始得分w[i], 剩余比赛场数r[i](包括与这n只队伍以外的队伍比赛), remain[i][j]表示队伍i与队伍j剩余比赛场数, 没有平局, 问 ...

  8. SGU 194. Reactor Cooling(无源汇有上下界的网络流)

    时间限制:0.5s 空间限制:6M 题意: 显然就是求一个无源汇有上下界的网络流的可行流的问题 Solution: 没什么好说的,直接判定可行流,输出就好了 code /* 无汇源有上下界的网络流 * ...

  9. SGU 194 Reactor Cooling ——网络流

    [题目分析] 无源汇上下界可行流. 上下界网络流的问题可以参考这里.↓ http://www.cnblogs.com/kane0526/archive/2013/04/05/3001108.html ...

随机推荐

  1. Matrix(类似kruskal)

    Matrix Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submis ...

  2. 13-7-1 做了一个360优化大师的主页(就是一个主页UI)

    模仿360优化大师做了一个下它的首页.   代码如下: <RelativeLayout xmlns:android="http://schemas.android.com/apk/re ...

  3. 可解压带中文名称文件的zip包

    package com.text.ziptest; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; i ...

  4. Android上下左右滑动,显示底层布局

    转载博客地址:http://www.cnblogs.com/flyme2012/p/4106308.html 闲着没事做了一个小东西.Android的上下左右滑动,显示底层布局.可以做类似于QQ消息列 ...

  5. grep -v grep 代表在查询的最终结果中去掉grep命令本身

    grep -v grep 代表在查询的最终结果中去掉grep命令本身

  6. Android Every day a new function:two

    分享功能: 效果图: 代码(分享TEXT,视频或者图片设置type即可): @Override protected void onCreate(Bundle savedInstanceState) { ...

  7. HTML前端技术(JS的使用,包括数组和字符串)

    <script type="text/javascript"> /* JS 数组的操作 //concat 连接两个或更多的数组,并返回结果. var arr1 = ne ...

  8. php中禁止非法调用和硬路径引入文件的方法

    php中禁止非法调用和硬路径引入文件的方法 在php中有一些公共的文件为了方便,我们会做一个公共文件,让不用的文件共同调用.为了禁止公共文件被非常单独调用,可以在文件上做一个常量,禁止非常调用:在公共 ...

  9. Httpwatch 工具介绍

    一 概述: HttpWatch强大的网页数据分析工具.集成在Internet Explorer工具栏.包括网页摘要.Cookies管理.缓存管理.消息头发送/接受.字符查询.POST 数据和目录管理功 ...

  10. SQL Server 启用与禁止触发器

    启用: disable trigger trigger_name on {objectName | database_name | server}; 禁用: enable trigger trigge ...