# 旅行商(TSP)

### Description

Shrek is a postman working in the mountain, whose routine work is sending mail to n villages. Unfortunately, road between villages is out of repair for long time, such that some road is one-way road. There are even some villages that can’t be reached from any other village. In such a case, we only hope as many villages can receive mails as possible.

Shrek hopes to choose a village A as starting point (He will be air-dropped to this location), then pass by as many villages as possible. Finally, Shrek will arrived at village B. In the travelling process, each villages is only passed by once. You should help Shrek to design the travel route.

### Input

There are 2 integers, n and m, in first line. Stand for number of village and number of road respectively.

In the following m line, m road is given by identity of villages on two terminals. From v1 to v2. The identity of village is in range [1, n].

### Output

Output maximum number of villages Shrek can pass by.

Input

4 3
1 4
2 4
4 3

Output

3

### Restrictions

1 <= n <= 1,000,000

0 <= m <= 1,000,000

These is no loop road in the input.

Time: 2 sec

Memory: 256 MB

### Hints

Topological sorting

### 描述

Shrek是一个大山里的邮递员，每天负责给所在地区的n个村庄派发信件。但杯具的是，由于道路狭窄，年久失修，村庄间的道路都只能单向通过，甚至有些村庄无法从任意一个村庄到达。这样我们只能希望尽可能多的村庄可以收到投递的信件。

Shrek希望知道如何选定一个村庄A作为起点（我们将他空投到该村庄），依次经过尽可能多的村庄，路途中的每个村庄都经过仅一次，最终到达终点村庄B，完成整个送信过程。这个任务交给你来完成。

### 限制

1 ≤ n ≤ 1,000,000

0 ≤ m ≤ 1,000,000

### 提示

 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 #include #include using namespace std; int * u; int * v; int * first; int * next; bool * visited; int * village_value; int n,m; void DFS(int start){     visited[start]=true;     for(int e=first[start];e!=-1;e=next[e]){         if(!visited[v[e]]){             DFS(v[e]);         }         if(village_value[start]>n>>m;     u=new int[m];     v=new int[m];     first=new int[n+1];     next=new int[m];     visited=new bool[n+1];     village_value=new int[n+1];     memset(first,-1,sizeof(int)*(n+1));     memset(village_value,0,sizeof(int)*(n+1));     memset(visited,false,sizeof(bool)*(n+1));     for(int e=0;e>u[e]>>v[e];         next[e]=first[u[e]];         first[u[e]]=e;     }     for(int i=1;i<=n;i++){         int t=0;         if(!visited[i])DFS(i);     }     int max_v=0;     for(int i=1;i<=n;i++){         if(village_value[i]>max_v)max_v=village_value[i];     }     cout<