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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Skiing(2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H)

發(fā)布時(shí)間:2025/3/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Skiing(2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Problem Description

In this winter holiday, Bob has a plan for skiing at the mountain resort.

This ski resort has?M?different ski paths and?N?different flags situated at those turning points.

The?ii-th path from the?Si?-th flag to the?Ti?-th flag has length?Li?.

Each path must follow the principal of reduction of heights and the start point must be higher than the end point strictly.

An available ski trail would start from a flag, passing through several flags along the paths, and end at another flag.

Now, you should help Bob find the longest available ski trail in the ski resort.

Input

The first line contains an integer?T, indicating that there are?T?cases.

In each test case, the first line contains two integers?N?and?M?where?0<N≤10000?and?0<M≤100000as described above.

Each of the following?M?lines contains three integers?Si?,?Ti?, and?Li??(0<Li?<1000)?describing a path in the ski resort.

Output

For each test case, ouput one integer representing the length of the longest ski trail.

Sample?Input

1
5 4
1 3 3
2 3 4
3 4 1
3 5 2

???????Sample????????Output

6

題意:t 組數(shù)據(jù),每組給出一個(gè) n 個(gè)點(diǎn) m 條邊的帶權(quán)有向圖,問整個(gè)圖的最長(zhǎng)路

思路:DAG 圖求最長(zhǎng)路,利用拓?fù)渑判騺斫鉀Q即可

Source Program

#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #include<bitset> #define EPS 1e-9 #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long #define Pair pair<int,int> const int MOD = 1E9+7; const int N = 50000+5; const int dx[] = {1,-1,0,0,-1,-1,1,1}; const int dy[] = {0,0,-1,1,-1,1,-1,1}; using namespace std;struct Node{int to,dis;Node(){}Node(int to,int dis):to(to),dis(dis){} }; vector<Node> G[N]; int in[N]; int dis[N]; int n,m;void topSort() {stack<int > S;for(int i=1; i<=n; i++)if(!in[i])S.push(i);while(!S.empty()) {int x=S.top();S.pop();for(int j=0; j<G[x].size(); j++) {int y=G[x][j].to;dis[y]=max(dis[y],dis[x]+G[x][j].dis);in[y]--;if(!in[y])S.push(y);}} }int main() {int T;scanf("%d",&T);while(T--){scanf("%d%d",&n,&m);memset(in,0,sizeof(in));memset(dis,0,sizeof(dis));for(int i=0; i<=n; i++)G[i].clear();for(int i=1; i<=m; i++) {int x,y,dis;scanf("%d%d%d",&x,&y,&dis);Node temp;temp.to=y;temp.dis=dis;in[y]++;G[x].push_back(temp);}topSort();int res=-INF;for(int i=1;i<=n;i++)res=max(res,dis[i]);printf("%d\n",res);}return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的Skiing(2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。