schlnet Tarjan strongly connected components

schlnet

★★★ input file: schlnet.in Output File: schlnet.out    simple to ratio of
the time limit: 1 s memory limit: 128 MB

description

Some schools even into a computer network. Those schools have entered into an agreement: each school will give some other school distribution software (referred to as " the schools " ). Note that if B in A distribution list of schools, then A need not also B schools list.

You want to write a program to calculate, according to the agreement, in order to make the network all schools use the new software, new schools must accept a minimum number of copies of the Software (subtasks A ). Furthermore, we wanted to determine through a school to send any new software, which will be distributed to all schools in the network. To accomplish this task, we may have to expand the school to receive lists to new members. Calculate the minimum necessary to increase the number of extensions that make us no matter which school to send new software, it will reach all the remaining schools (subtasks B ). An extension is the introduction of a new member in the school receives a school list.

INPUT FORMAT (file schlnet.in)

The first line of the input file comprises an integer N : the number of school network ( 2 <= N <= 100 ). Schools with former N logo is a positive integer. Next N Each row represents a row in the receiving school list (distribution list). Of the i + 1 row including schools i receiving an identifier of the school. Each list with 0 end. Empty list only a 0 representation.

OUTPUT FORMAT(file schlnet.out)

Your program should output two lines in the output file. The first line should contain one positive integer: subtasks A solution. The second line should contain subtasks B solution.

SAMPLE INPUT (file schlnet.in)


2 4 3 0
4 5 0
0

1 0

SAMPLE OUTPUT (file schlnet.out)

1
2

 

 

 

QAQ exam simulation game to sum up a little waste solution to a problem it

The questions is clearly a Tarjan (although I will write Tarjan but I do not how to deal with the questions QAQ)

 

 

Positive solution to this questions is like this

It is the first to shrink by Tarjan point

Then the first question

In order to make the network in all schools use the new software, new schools must accept a minimum number of copies of the Software (subtasks A) is to find the point of view of the entire shrink finished in a few degrees to the point 0 (Aoao wailing I At that time how did not think ah ~ ~)

 

second question

Calculate the minimum necessary to increase the number of extensions, so that no matter which school to send our new software, it will reach all the remaining schools (subtasks B)

An extension is the introduction of a new member in the school receives a school list.

It is coupled with a few side

Positive solution of this problem is actually track max (the degree of the number of point 0, a point is the number of 0's)

(I was struggling to write code)

Guess you like

Origin www.cnblogs.com/Tidoblogs/p/11324968.html