Codevs original plagiarism question 5969 [AK] burning a CD, codevs5969
DescriptionDescription
• At the end of the FJOI2010 summer camp, many campers proposed to burn the materials for the entire summer camp into a CD for everyone to continue learning. The organizing committee thinks this idea is good! However, the organizing committee does not have enough empty discs at the moment to ensure that everyone can get the discs for storing data. What should we do ?! • DYJ analyzed the relationship between all operators and found that some operators are in one city. In fact, they only need one, because after one person gets the CD, others can copy something like a USB flash drive! • They would like some people to copy materials to them, and may not want others to copy materials to them, which is out of sync with the team spirit we promoted by FJOI !!! • Assume that there are a total of N operators (2 <= N <= 200), each of which is numbered 1 ~ N. DYJ sent a questionnaire to each user, asking each clerk to fill in who he was willing to copy the information. Of course, if A is willing to copy the data to B and B is willing to copy the data to C, B and C will obtain the data once A obtains the data. • Now, please write a program to help DYJ calculate the minimum number of CDs to be burned by the organizing committee based on the collected questionnaire to ensure that all camp members can get the materials for the summer camp after they go back?
Input description
Input Description
First, a numberN, NextNLine, indicating that each camper is willing to copy the information they have obtained to other camper. That is,I + 1The row indicatesIA camper is willing to copy the information to the camp operator's number0End. If a camper is unwilling to copy data to anyThe corresponding row is only1Items0Multiple numbers in a row are separated by a space.
Output description
Output Description
A positive integer that indicates the minimum number of discs to be burned.
Sample Input
Sample Input
5
2 4 3 0
4 5 0
0
0
1 0
Sample output
Sample Output
1
Data range and prompt
Data Size & Hint
2 <= N <= 200
Idea: Flyoed + KO violence
Note that the nmap array may be written as nmap [j] [I] = 1 at the beginning, but not actually, if nmap [j] [I] = 1, the extreme data will go wrong, and I don't know why.
Theoretically, the so nmap array can be removed.
Poor data ......
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const int maxn=0x7fffffff; 6 int map[101][101]; 7 int nmap[101][101]; 8 int n; 9 int vis[101]; 10 int pass[101]; 11 int now=1; 12 int tot; 13 void dfs(int p) 14 { 15 vis[p]=1; 16 for(int i=1;i<=n;i++) 17 { 18 if(vis[i]==0&&map[p][i]==1) 19 { 20 dfs(i); 21 } 22 } 23 pass[now]=p; 24 now++; 25 } 26 void ndfs(int p) 27 { 28 vis[p]=0; 29 for(int i=1;i<=n;i++) 30 { 31 if(vis[i]==1&&nmap[p][i]==1) 32 { 33 ndfs(i); 34 } 35 } 36 } 37 int main() 38 { 39 for(int i=1;i<=101;i++) 40 for(int j=1;j<=101;j++) 41 { 42 map[i][j]=maxn; 43 nmap[i][j]=maxn; 44 } 45 scanf("%d",&n); 46 for(int i=1;i<=n;i++) 47 { 48 int j; 49 while(scanf("%d",&j)) 50 { 51 if(j==0) 52 break; 53 else 54 { 55 map[i][j]=1; 56 nmap[i][j]=1; 57 } 58 } 59 } 60 for(int k=1;k<=n;k++) 61 { 62 for(int i=1;i<=n;i++) 63 { 64 for(int j=1;j<=n;j++) 65 { 66 if(map[i][k]!=maxn&&map[k][j]!=maxn) 67 { 68 map[i][j]=map[i][j]||(map[i][k]+map[k][j]); 69 nmap[i][j]=nmap[i][j]||(nmap[i][k]+nmap[k][j]); 70 } 71 /*if(map[i][j]>map[i][k]+map[k][j]) 72 { 73 map[i][j]=map[i][k]+map[k][j]; 74 } 75 if(nmap[i][k]!=maxn&&nmap[k][j]!=maxn) 76 { 77 if(nmap[i][j]>nmap[i][k]+nmap[k][j]) 78 { 79 nmap[i][j]=nmap[i][k]+nmap[k][j]; 80 } 81 }*/ 82 } 83 } 84 } 85 memset(vis,0,sizeof(vis)); 86 for(int i=1;i<=n;i++) 87 { 88 if(vis[i]==0) 89 { 90 dfs(i); 91 } 92 } 93 for(int i=n;i>=1;i--) 94 { 95 if(vis[pass[i]]==1) 96 { 97 ndfs(pass[i]); 98 tot++; 99 }100 }101 printf("%d",tot);102 return 0;103 }