日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

洛谷 1137 旅行计划

發布時間:2023/12/2 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 洛谷 1137 旅行计划 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

【題解】

  拓撲排序+DP即可。

1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<vector> 5 #define LL long long 6 #define rg register 7 #define N 200010 8 using namespace std; 9 int n,m,front,rear,q[N],f[N],in[N]; 10 bool vis[N]; 11 vector<int>to[N]; 12 inline int read(){ 13 int k=0,f=1; char c=getchar(); 14 while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar(); 15 while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar(); 16 return k*f; 17 } 18 inline void topu(int x){ 19 f[x]=max(f[x],1); vis[x]=1; q[front=rear=1]=x; 20 while(front<=rear){ 21 int u=q[front]; 22 for(rg int i=0,v;i<(int)to[u].size();i++){ 23 in[v=to[u][i]]--; f[v]=max(f[v],f[u]+1); 24 if(!in[v]){vis[v]=1; q[++rear]=v;} 25 } 26 front++; 27 } 28 } 29 int main(){ 30 n=read(); m=read(); 31 for(rg int i=1;i<=m;i++){ 32 int u=read(),v=read(); 33 to[u].push_back(v); in[v]++; 34 } 35 for(rg int i=1;i<=n;i++)if(!vis[i]&&!in[i]) topu(i); 36 for(rg int i=1;i<=n;i++) printf("%d\n",f[i]); 37 return 0; 38 }

?

轉載于:https://www.cnblogs.com/DriverLao/p/9863639.html

總結

以上是生活随笔為你收集整理的洛谷 1137 旅行计划的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。