[Bzoj 1143] [CTSC 2008] Sacrificial River (the largest independent set of two graphs)

Source: Internet
Author: User

Title Link: http://www.lydsy.com:808/JudgeOnline/problem.php?id=1143

This is my first ctsc problem, the water I was shocked ... It is said that Bzoj only the first question, did not ask the second question, because no data, no wonder so water ...

First we need to know the concept of a separate set of binary graphs :

The independent set of a binary graph is a set of vertices that are not connected to any two points in a binary graph.

maximum independent set method for binary graphs :

Maximum independent set of binary graphs = two points-two graph maximum matching

And then this is a good question to do. First, we use the Floyd to find the point pairs of points to each other, and then use these points to create a two-point graph, the two points in the two-point graph, the side of the link is mutually accessible. Then we can find the maximum independent set of the binary graph. The maximum independent concentration of the obtained binary graph is not reached between any two points.

Pay attention to the number of sides to open a n^2! Because the limit condition is between any two points can be reached

#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include < algorithm> #define MAXV 110#define maxe 100100using namespace std;struct edge{int u,v,next;} Edges[maxe];int head[maxv],ncount=0;int dist[maxv][maxv],n,m;int linky[maxv];bool visit[MAXV];void AddEdge (int U,int    V) {edges[++ncount].u=u;    Edges[ncount].v=v;    Edges[ncount].next=head[u]; Head[u]=ncount;}        bool Dfs (int u) {for (int p=head[u];p!=-1;p=edges[p].next) {int v=edges[p].v;        if (Visit[v]) continue;        Visit[v]=true; if (linky[v]==-1| |            DFS (Linky[v])) {linky[v]=u;        return true; }} return false;}    int main () {memset (head,-1,sizeof (head));    memset (linky,-1,sizeof (linky));    scanf ("%d%d", &n,&m);    int ans=n;        for (int i=1;i<=m;i++) {int x, y;        scanf ("%d%d", &x,&y);    Dist[x][y]=1;        } for (int k=1;k<=n;k++)//floyd preprocessing, find the point pair (u,v) that you can reach V; Forint i=1;i<=n;i++) for (int j=1;j<=n;j++) dist[i][j]|=dist[i][k]&dist[k][j];                    for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (i!=j) if (Dist[i][j])    Addedge (I,J);        for (int i=1;i<=n;i++) {memset (visit,false,sizeof (visit));    if (Dfs (i)) ans--;    } printf ("%d\n", ans); return 0;}




[Bzoj 1143] [CTSC 2008] Sacrificial River (the largest independent set of two graphs)

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.