For the age relationship between n people, ask at least a few groups so that the age of each person in each group cannot be directly or indirectly compared.
People in each Unicom block have to be assigned to different groups. After the point is scaled down, find the longest chain, that is, the answer.
Tarjian contraction point + dp find the longest path
Grouping Time Limit: 2 Seconds Memory Limit: 65536 KB
Suppose there areNPeople in ZJU, whose ages are unknown. We have some messages about them.I-Th message shows that the age of personSiIs not smaller than the age of personTi. Now we need to divide all theseNPeople into several groups. one's age shouldn't be compared with each other in the same group, directly or indirectly. and everyone shoshould be assigned to one and only one group. the task is to calculate the minimum number of groups that meet the requirement.
Input
There are multiple test cases. For each test case: The first line contains two integersN(1 ≤N≤ 100000 ),M(1 ≤M≤ 300000 ),NIs the number of people, andMIs the number of messages. Then followedMLines, each line contain two integers si and ti. There is a blank line between every two cases. Process to the end of input.
Output
For each the case, print the minimum number of groups that meet the requirement one line.
Sample Input
4 41 21 32 43 4
Sample Output
3
Hint
Set1 = {1}, set2 = {2, 3}, set3 = {4}
Author: LUO, Jiewei
Source: ZOJ Monthly, Jun 2014
#include
#include
#include
#include using namespace std;const int maxn=100100;typedef pair
pII;struct Edge{ int to,next;}edge[maxn*3];pII bian[maxn*3];int Adj[maxn],Size;int n,m;void init(){ Size=0;memset(Adj,-1,sizeof(Adj));}void Add_Edge(int u,int v){ edge[Size].to=v; edge[Size].next=Adj[u]; Adj[u]=Size++;}int Low[maxn],DFN[maxn],Stack[maxn],Belong[maxn],num[maxn];int Index,top,scc;bool Instack[maxn];void tarjan(int u,int fa){ int v; Low[u]=DFN[u]=++Index; Stack[top++]=u; Instack[u]=true; for(int i=Adj[u];~i;i=edge[i].next) { v=edge[i].to; // if(v==fa) continue; if(!DFN[v]) { tarjan(v,u); Low[u]=min(Low[u],Low[v]); } else if(Instack[v]) { Low[u]=min(Low[u],DFN[v]); } } if(Low[u]==DFN[u]) { scc++; do { v=Stack[--top]; Instack[v]=false; num[scc]++; Belong[v]=scc; }while(v!=u); }}void solve(){ memset(DFN,0,sizeof(DFN)); memset(Instack,0,sizeof(Instack)); memset(num,0,sizeof(num)); Index=scc=top=0; for(int i=1;i<=n;i++) { if(!DFN[i]) tarjan(i,i); }}/*void debug(){ cout<<"scc: "<