The Nocow is very good. http://www.nocow.cn/index.php/USACO/schlnet
How to find the strong connected component? For this problem, you can use Floyd directly before you judge.
----------------------------------------------------------------------------------
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>
#define REP (i,r) for (int i=0;i<r;i++)#define CLR (x,c) memset (x,c,sizeof (x) )#define REP (I,L,R) for (int i=l;i<r;i++)
using namespace std;
const int maxn=100+5;
int P[MAXN];int MAP[MAXN][MAXN];int IN[MAXN],OUT[MAXN];bool OK[MAXN];int n;
void init () {CLR (map,0); CLR (in,0); CLR (out,0); CLR (ok,0) ;cin>>n;Rep (i,n) p[i]=i;int t;Rep (i,n)while (scanf ("%d", &t) && t) map[i][--t]=1;}
int find (int x) {return x==p[x]? X:p[x]=find (P[x]);}
void Work () {Rep (k,n)Rep (i,n)Rep (j,n) if (Map[i][k] && map[k][j]) map[i][j]=1;Rep (i,n)Rep (J,i+1,n) if (Map[i][j] && map[j][i]) P[i]=find (j);Rep (i,n) {int X=find (i);ok[x]=1;Rep (j,n) {int Y=find (j);if (x==y) continue;if (map[i][j]) out[x]++;if (map[j][i]) in[x]++;}}
int cnt[2]={0,0},pd=-1;Rep (i,n) if (Ok[i]) {pd++;if (!in[i]) cnt[0]++;if (!out[i]) cnt[1]++;}if (PD) printf ("%d\n%d\n", Cnt[0],max (Cnt[0],cnt[1]));Else printf ("1\n0\n");}
int main (){freopen ("schlnet.in", "R", stdin);freopen ("Schlnet.out", "w", stdout);init ();Work ();return 0;}
----------------------------------------------------------------------------------
Network of schools
IOI ' 1 Problem 3
A number of schools is connected to a computer network. Agreements has been developed among those Schools:each School maintains a list of schools to which it distributes Softwa Re (the "Receiving schools"). Note that if B is in the distribution list of school A, then a does not necessarily appear in the list of school B.
You is to write a program this computes the minimal number of schools that must receive a copy of the new software in Ord Er for the software to reach all schools in the network according to the agreement (Subtask A). As a further task, we want to ensure is sending the copy of new software to an arbitrary school, this software would r Each of the schools in the network. To achieve this goal we are having to extend the lists of receivers by new members. Compute the minimal number of extensions that has to is made so this whatever school we send the new software to, it'll Reach all other schools (Subtask B). One extension means introducing one new member into the list of receivers of one school.
Program Name:schlnetinput FORMATThe first line of the input file contains a integer n:the number of schools in the network (2<=N<=100). The schools is identified by the first N positive integers. Each of the next N lines describes a list of receivers. The line i+1 contains the identifiers of the receivers of school I. Each list is ends with a 0. An empty list contains a 0 alone in the line.
SAMPLE INPUT (file schlnet.in)
OUTPUT FORMAT
Your program should write, lines to the output file. The first line should contain one positive integer:the solution of subtask A. The second line should contain the solution of subtask B.
SAMPLE OUTPUT (file schlnet.out)
1 2
[IOI1996] Usaco Section 5.3 Network of schools (strongly connected components)