2776 looking for representative Yuan
time limit: 1 sspace limit: 256000 KBtitle level: Golden Gold SolvingTitle Description
Description
Guangzhou second middle Su Yuan Experimental school has a total of n societies, numbered 1 to n respectively.
Guangzhou second middle Su Yuan Experimental school has a total of M individuals, which are numbered 1 to M respectively. Each person may participate in one or more societies, or may not participate in any community.
Each community needs to choose a representative. Brother Qian wants more people to be represented.
Enter a description
Input Description
The first line enters two numbers n and M.
The following n rows have a number of rows per line, and these numbers are positive integers that do not exceed M. Where the number of line I represents all members of the community I. Each line ends with a 0.
Output description
Output Description
The maximum number of people that can be represented is the output.
Sample input
Sample Input
4 4
1 2 0
1 2 0
1 2 0
1 2 3) 4 0
Sample output
Sample Output
3
Data range and Tips
Data Size & Hint
Each test point 1s
Data range
n,m<=200
Category labels
Tags Click here to expandOn the matching graph of binary graphs
#include <cstdio>#include<cstring>#include<iostream>using namespacestd;#defineN 210intE[n][n],vis[n],match[n];intN,m,k,t,ans;intDfsintu) { for(intI=1; i<=m;i++){ if(e[u][i]&&!Vis[i]) {Vis[i]=1; if(!match[i]| |DFS (Match[i])) {Match[i]=u; return 1; } } } return 0;}intMain () {scanf ("%d%d",&n,&m); for(intI=1, j;i<=n;i++){ while(SCANF ("%d", &j) = =1&&j) {E[i][j]=1; } } for(intI=1; i<=n;i++) {memset (Vis,0,sizeofvis); if(Dfs (i)) ans++; } printf ("%d\n", ans); return 0;}
1222 Letter and Envelope questions
time limit: 1 sspace limit: 128000 KBtitle level: Diamonds Diamond SolvingTitle Description
Description
Mr. John wrote n letters in the evening, and wrote n envelopes accordingly to install the letter, ready to send it. But the next day John's son, John Small, took all the n letters out of the envelope. Unfortunately, Small John was unable to properly put the letter back into the envelope.
The n letters provided by small John are sequentially numbered 1,2,...,n, and N envelopes are numbered 1,2,...,n. Suppose small John can provide a set of information: The letter I is definitely not in the envelope J. Please program help small John to correctly load the letter back into the envelope as much as possible.
Enter a description
Input Description
The first line of the n file is an integer n (n≤100). Letters and envelopes are sequentially numbered 1,2,...,n.
n each row in the next row has 2 numbers I and J, indicating that the letter I letter is definitely not in the J envelope. The last line of the file is 2 0, which indicates the end.
Output description
Output Description
Each line of the output file has 2 numbers I and J, indicating that the letter I letter must be in the J envelope. Please press the letter number I from small to large sequential output. If you are unsure of any correspondence to properly load the envelope, the output is "none".
Sample input
Sample Input
3
1 2
1 3
2 1
0 0
Sample output
Sample Output
1 1
Data range and Tips
Data Size & HintCategory labels
Tags Click here to expandOn the matching graph of binary graphs
/*This is a two-figure matching of the variable, if an edge is not missing, then no it must not be perfect match, thus can be pushed to first match, and then the matching edge in turn delete, if not perfect match on the output*/#include<cstdio>#include<cstring>#include<iostream>using namespacestd;#defineN 101intE[n][n],vis[n],lkx[n],lky[n];intN,m,x,y,ans;intDfsintu) { for(intI=1; i<=n;i++){ if(!e[u][i]&&!Vis[i]) {Vis[i]=1; if(!lky[i]| |DFS (Lky[i])) {Lky[i]=u; Lkx[u]=i; return 1; } } } return 0;}intMain () {scanf ("%d",&N); while(SCANF ("%d%d", &x,&y) = =2&&x&&y) e[x][y]=1; for(intI=1; i<=n;i++) {memset (Vis,0,sizeofvis); if(Dfs (i)) ans++; } if(ans!=n) printf ("none\n"); Else{ BOOLflag=0; for(intI=1; i<=n;i++){ intt=Lkx[i]; memset (Vis,0,sizeofvis); E[i][t]=1; Lky[t]=lkx[i]=0; if(!DFS (i)) {printf ("%d%d\n", i,t); Lky[t]=i;lkx[i]=t;flag=1; } E[i][t]=0; } if(!flag) printf ("none\n"); } return 0;}
Codevs must do: 2776, 1222