The main topic: Give a perfect match of a binary map (Prince and Princess Burn Dead List table), the second figure X and Y are only n points, ask for each x point, he can choose which points match with it, after matching, the maximum match of the remaining graph is still n
Idea: This is the Great White Book 379-page two-dimensional graph of the pressure axis, in the picture of the brush problem has not long thought about this problem, it is not difficult to think now
The noticeable point of this question is that the initial matching of a binary graph is given beforehand.
After the enumeration of each point is obviously not feasible, then it is still a classic way of thinking about graph theory, the point and the side of each expression of what
The input of the topic naturally gives a diagram, but it seems useless to the question, so began to think about the initial match given to each side as a point!!!
The figure that makes up each point is the pairing of a prince and a princess, and if a prince can still love the princess other than the original matching princess, then from this point to the princess with a side
Then obviously the new composition of the diagram if there is a ring, (A to b,b and can go to a), then we can be the original binary map in the match sequentially along a lattice (image is the Prince in the ring in the first match of the girl to the next prince), so certainly do not change the maximum number of binary graph match
Then it is thought that in a strong connected component, any two points must be ring, so it can be shrunk, a girl in an SCC can certainly be taken, not a girl in an SCC because it is a dag, it is impossible to have a ring, so it cannot be taken anyway
And then it's a, and the output is incremented so it contributes to the FA WA
#include <cstdio>
#include <string.h>
#include <iostream>
#include <algorithm>
#define MAXN 600090
using namespace Std;
int head[maxn],next[maxn],point[maxn],now=0;
int STACK[MAXN],TOP,COL,DFN[MAXN],LOW[MAXN];
int TIM,BELONG[MAXN],X[MAXN],Y[MAXN];
int match[maxn],ans[maxn],h=0,idx=0;
BOOL INSTACK[MAXN];
void Add (int x,int y)
{
NEXT[++NOW]=HEAD[X];
Head[x]=now;
Point[now]=y;
}
void Tarjan (int k)
{
Stack[++top]=k;
Dfn[k]=low[k]=++tim;
Instack[k]=1;
for (int i=head[k];i;i=next[i])
{
int u=point[i];
if (dfn[u]==0)
{
Tarjan (U);
Low[k]=min (Low[k],low[u]);
}
else if (instack[u]==1)
{
Low[k]=min (Low[k],low[u]);
}
}
if (Dfn[k]==low[k])
{
col++;
int u;
Do
{
u=stack[top--];
Belong[u]=col;
instack[u]=0;
}while (U!=K);
}
}
int main ()
{
int n,k,tt;
scanf ("%d", &n);
for (int i=1;i<=n;i++)
{
scanf ("%d", &k);
for (int j=1;j<=k;j++)
{
scanf ("%d", &TT);
X[++h]=i;y[h]=tt;
}
}
for (int i=1;i<=n;i++)
{
scanf ("%d", &TT);
Match[tt]=i;
}
for (int i=1;i<=h;i++)
{
if (Match[y[i]]!=x[i])
{
Add (X[i],match[y[i]]);
}
}
for (int i=1;i<=n;i++) if (dfn[i]==0) Tarjan (i);
for (int i=1;i<=n;i++)
{
int hh=0;
while (x[idx+1]==i && idx+1<=h)
{
idx++;
if (Belong[i]==belong[match[y[idx]])
ANS[++HH]=Y[IDX];
}
printf ("%d", HH);
Sort (ANS+1,ANS+1+HH);
for (int i=1;i<=hh;i++)
{
printf ("%d", ans[i]);
}
printf ("\ n");
}
return 0;
}
POJ 1904:king ' s Quest "Tarjan"