每个点肯定是它上个点转移过来的
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
vector<int>a[N];
int d[N],dp[N];
void solve(){
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
a[u].push_back(v);
d[v]++;
}
queue<int>q;
for(int i=1;i<=n;i++){
if(!d[i]){
q.push(i);
}
}
while(q.size()){
int t=q.front();
q.pop();
for(auto c:a[t]){
dp[c]=max(dp[c],dp[t]+1);
d[c]--;
if(!d[c])q.push(c);
}
}
int ans=0;
for(int i=1;i<=n;i++){
ans=max(ans,dp[i]);
}
cout<<ans;
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
标签:const,int,back,1e5,Longest,Path
From: https://www.cnblogs.com/yufan1102/p/17924287.html