Members ' secret

Source: Internet
Author: User

3 . Congressman Secret

(Secret.pas/c/cpp)

"Problem description"

A state-owned N-member, big-brother xDD to choose from a portion of tea to talk about some things. There may be a contradiction between the two members, and the xDD do not wish to have any contradictions between the elected members, so much so that the tea-drinking scene is awkward.

It is known that there is M-contradiction between these members, can you help the big guy xDD figure out how many senators he can choose to drink tea to talk about?

If you think of the legislators as a point of view, and regard the contradiction as an edge, then the data in the question guarantees that m does not have a ring with more than 3 points in the diagram of the contradiction. (Figure 1 meets the requirements, Figure 2 does not match)

"Input Data"

The first line of the input file is a space-delimited two integers n and m, indicating a total of N members who have m-pairs of contradictions between them. The next M-line, each row will have a pair of integers a and B (separated by a space), indicating that senator A has a contradiction with Senator B. The input data is guaranteed to be free of heavy edges and self-loops. (members are numbered starting from 1)

"Output Data"

Output a line containing an integer, that is, the big guy XDD can select the maximum number of members to drink tea to talk about things.

"Input and Output sample"

Secret.in

5 6

1 2

3 2

1 3

3 5

3 4

4 5

Secret.out

2

"Sample description"

6 members of a state, 1-2-3 of the contradictions in the formation of a ring, 3-4-5 to form a ring, so can only be selected in the two ring of a member, and cannot choose the number 3rd.

"Data size and conventions"

For 20% of data, 1≤n≤20

For 40% of data, 1≤n≤50

For 100% of data, 1≤n≤200

Input data is guaranteed to be legal.

———————————————————— I'm a split line ————————————————————————

DP topic. It is said to be a tree-like (cactus??? )。

DP[I][J] denotes the first point, the choice (j==1) or the case of a non-selective (j==0).

Note that the problem is not guaranteed unicom, it is possible that the forest.

Write the memory search, the code is as follows:

1 /*2 problem:3 OJ:4 USER:S.B.S.5 Time :6 Memory:7 Length:8 */9#include <iostream>Ten#include <cstdio> One#include <cstring> A#include <cmath> -#include <algorithm> -#include <queue> the#include <cstdlib> -#include <iomanip> -#include <cassert> -#include <climits> +#include <functional> -#include <bitset> +#include <vector> A#include <list> at #defineF (i,j,k) for (register int i=j;i<=k;++i) - #defineM (A, B) memset (A,b,sizeof (a)) - #defineFF (i,j,k) for (register int i=j;i>=k;i--) - #defineMAXN 210 - #defineINF 0x3f3f3f3f - #defineMAXM 4001 in #defineMoD 998244353 - #defineLOCAL to using namespacestd; + intRead () { -     intx=0, f=1;CharCh=GetChar (); the      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} *      while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} $     returnx*F;Panax Notoginseng } - intn,m; the intfa[maxn],dp[maxn][2]; + BOOLTREE[MAXN][MAXN]; A BOOLVIS[MAXN],MP[MAXN][MAXN]; theInlinevoidDfsintu) + { -vis[u]=true; $F (I,1, N) { $         if(!vis[i]&&Mp[u][i]) { -tree[u][i]=1; -fa[i]=u; the DFS (i); -         }Wuyi     } the } -InlineintSolveintUintv) Wu { -     intCNT; About     if(dp[v][u]!=-1)returnDp[v][u]; $     if(u==0){ -Cnt=0; -F (I,1, N)if(Tree[v][i]) Cnt+=max (Solve (0, i), Solve (1, i)); -         returndp[v][u]=CNT; A     } +     Else{ the         BOOLTEMP[MAXN]; M (temp,0); -F (I,1, N) { $             if(Tree[v][i]) { thetemp[i]=true; theF (J,1, N)if(Tree[i][j]&&mp[v][j]) temp[j]=true; the             } the         } -Cnt=0; inF (I,1, N)if(!temp[i]&&fa[i]!=-1&&Temp[fa[i]]) theCnt+=max (Solve (0, i), Solve (1, i)); the         returndp[v][u]=cnt+1; About     } the } the intans; the intMain () + { -Std::ios::sync_with_stdio (false);//cout<<setiosflags (ios::fixed) <<setprecision (1) <<y; the #ifdef LOCALBayiFreopen ("Input.txt","R", stdin); theFreopen ("output.txt","W", stdout); the     #endif -Cin>>n>>m; -M (dp,-1); M (fa,-1); theF (I,1, m) {inta,b;cin>>a>>b;mp[a][b]=mp[b][a]=1;} theF (I,1, N) { the         if(!Vis[i]) { the DFS (i); -Ans+=max (Solve (0, i), Solve (1, i)); the         } the     } thecout<<ans<<Endl;94     return 0; the}
3

Members ' secret

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.