SGU 242. Student ' s morning (network stream)

Source: Internet
Author: User

It's really troublesome to read the English question ... Understand test instructions spend more time than you think ... Bare network stream, we just limit each person to start traffic is 1, each university enters the traffic is at most 2, equivalent constructs the feasible solution.

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

#include <cstdio>#include <cstring>#include <algorithm>#include <cctype>using namespace std;const int MAXN = 209;const int MAXV =;inline int Read () {char C = getchar ();int ret = 0;For (;!isdigit (c); c = GetChar ());For (; IsDigit (c); c = GetChar ()) ret = RET * + 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->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;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;printf ("2%d%d\n", ++ans[x][0], ++ans[x][1]);} elseputs ("NO");return 0;}

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

242. Student ' s Morningtime limit per test:0.25 sec.
Memory limit per test:6144 Kbinput:standard
Output:standard


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

More formally, your task was, given numbers of students, selected universities and preference list of every student, to Dec IDE whether it is possible to visit all universities by at least the students or no, and if it is possible your must out Put for each university numbers of students, which has to go to it on one company. One student can ' t is in more than one company.
InputFirst line of input file contains 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.
OutputFirst line of output file must contain word "YES" (without quotes), if it possible-visit all universities, satisfying r Ules 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 is going to corresponding university. First number in List of students must is 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[submit][forum]
Author: Alexey Preobrajensky
Resource: ---
Date: October, 2003





SGU 242. Student ' s morning (network stream)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.