"Basic exercise" "topological sort" codevs3294 station classification

Source: Internet
Author: User

Source: The fourth question of NOIP2013 popularization



Title Description Description

A one-way railway line, numbered 1, 2, ..., N of n stations. Each station has a level, at least 1 levels. There are several trips on this line, each meeting the following requirements: If this train stops at Station X, then all levels greater than or equal to station x must be docked between the departure and terminal. (Note: The starting station and terminal are naturally counted as pre-known sites that need to be docked)
For example, the following table is the operation of 5 trips. Among them, the first 4 trips to meet the requirements, and the 5th trip due to stop at train station 3rd (level 2) but did not stop at the 6th train station (also 2 level) and do not meet the requirements.

The operation of the existing M-Train (all meet the requirements), try to calculate that the N train station at least a few different levels.

Enter a description input Description

The first line contains 2 positive integers n, m, separated by a space.
In line i+1 (1≤I≤M), the first is a positive integer s_i (2≤s_i≤n), which indicates that there are s_i stops for the trip train, and then there are s_i positive integers, which indicate the numbering of all the stations, from small to large. Each of the two numbers is separated by a space. Enter to ensure that all trains meet the requirements.

outputs description output Description

The output has only one row and contains a positive integer, which is the minimum number of levels divided by the N train station.

sample input to sample

[Sample 1]
7 |
4 1 3) 5 6
3 3 5 6
[Sample 2]
7}
4 1 3) 5 6
3 3 5 6
3 1 5 9

Sample output Sample outputs

[Sample 1]
2
[Sample 2]
3

data size & Hint

For 20% of data, 1≤n, m≤10;
For 50% of data, 1≤n, m≤100;
For 100% of data, 1≤n, m≤1000.

This topic Li Chen said a look is topology I looked at a long while did not see the others said just want to understand ⊙﹏⊙ B Khan ashamed Ah

The basic idea is that for each line his middle point does not pass through the level must be strictly less than the passing level so each point that has not passed points to each passing point to connect an edge so that a graph is more dense in the topological sort can be sorted out several layers of a few levels

The code that was written refers to the Huang long so basically the same but the first try all WA because ans=0 misplaced the position modified after WA was half in fact the reason here (the wrong code):

while (1) {int top=0;for (int i=1;i<=n;i++) {if (!r[i]) {r[i]=-1;top++;for (int j=1;j<=n;j++)   if (E[i][j])  {  e[i][j]=0;  R[j]--;//maybe it is 0 now! Here it is possible to generate a new 0 point, and this point should be the next level sorted out  }}}if (!top) break;ans++;

That means you can't find a point to deal with one that should be saved up for centralized processing


Then put the code



———————————————— no responsibility to split the line ————————————————

Because it is the preparation of the Noip, the topic of the graph theory ends here, of course, will be interspersed with some exercises.

Tarjan Shrink Point didn't learn, Li Chen said don't learn, so temporarily put down. LCA may still have to look at, have time to try the line Tree balance tree (angled 45 degrees to the sky ...) )

The next module is math. Euler function Inverse combination number All of this has to be learned.

Unconsciously blog verses accumulated a lot of ... It's amazing how you sort it out.

Children's Day Happiness Although it has passed the college entrance examination refueling prepare to move the building culture class also must refuel diligently test Tsinghua "=



Yier boat, avoid the continents, out of the North Sea, and then cross the Yangtze River, into the Suzhou Ocean, Stud, rooftop, and even jiasong.


"Basic exercise" "topological sort" codevs3294 station classification

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.