看英文题真是麻烦...理解题意花的时间比想的时间还长...裸的网络流, 我们只要限制每个人出发流量为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
  1.  
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
  1.  
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. Nginx基础教程PPT

    Nginx基础教程PPT By 马冬亮(凝霜  Loki) 一个人的战争(http://blog.csdn.net/MDL13412) pdf版本号下载 watermark/2/text/aHR0cD ...

  2. Android提高第十一篇之模拟信号示波器

    上次简单地介绍了AudioRecord和AudioTrack的使用,这次就结合SurfaceView实现一个Android版的手机模拟信号示波器(PS:以前也讲过J2ME版的手机示波器).最近物联网炒 ...

  3. SQL整理2

    数据库的概念 结构化查询语言:structured query language 简称:SQL 数据库管理系统:database management system 简称:DBMS 数据库管理员:da ...

  4. MSDN地址,记录下来,以防以后使用

    MSDN在线官网:https://msdn.microsoft.com/zh-cn/default.aspx 以备学习时候使用.

  5. oracle tablespace

    oracle tablespace 1. 查看所有表空间大小 SQL> select tablespace_name,sum(bytes)/1024/1024 from dba_data_fil ...

  6. OC中对象拷贝概念

    OC中的对象拷贝概念,这个对于面向对象语言中都会有这种的问题,只是不同的语言有不同的解决方式:C++中有拷贝构造函数,Java中需要实现Cloneable接口,在clone方法中进行操作.但是不过OC ...

  7. beego任务定时执行,延迟执行

    import ( "github.com/astaxie/beego" "github.com/astaxie/beego/toolbox") cronExpr ...

  8. C语言版推箱子

    推箱子源代码初步: #include<stdio.h> #include<conio.h> #include<stdlib.h> #define boolean i ...

  9. sass教程

    sass教程 1. 使用变量; sass让人们受益的一个重要特性就是它为css引入了变量.你可以把反复使用的css属性值 定义成变量,然后通过变量名来引用它们,而无需重复书写这一属性值.或者,对于仅使 ...

  10. 软件测试学习日志————round 0 An impressed error in my past projects

    在初学各种语言时总会出现各种错误,比如main携程mian.忘了加各种库,打错字等等等等.虽然这些错误后面看来很幼稚,但是有的时候真的会让人印象很深刻. 在初学JavaScript时,我对JavaSc ...