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

题目链接:点这里!

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

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

The ii-th path from the S_iSi​-th flag to the T_iTi​-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 Format

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

In each test case, the first line contains two integers NN and MM where 0 < N \leq 100000

Each of the following MM lines contains three integers S_iSi​, T_iTi​, and L_i~(0 < L_i < 1000)Li​ (0

Output Format

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

样例输入复制

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

样例输出复制

6

题意:给你n个点,m条滑道,接着m行代表任意两个点和她们之间的距离,求所有路径中最长的那条路径的长度!

思路:STL解决。

#include
#include
#include
#include
#include
using namespace std;
const int maxn = 1e4+10;
int in[maxn],d[maxn];
int n,m,u,v,w;
vector >G[maxn]; //注意pair的用法
void topsort()
{
    queueq;
    for(int i=1;i<=n;i++)
    {
        if(!in[i])
            q.push(i); //将入度为0的点加入队列
    }
    int now;
    while(!q.empty())
    {
        now=q.front(),q.pop();
        for(int i=0;i>t;
    while(t--)
    {
        cin>>n>>m;
        memset(d,0,sizeof(d));
        memset(in,0,sizeof(in));
        for(int i=1;i<=n;i++)
            G[i].clear();
        for(int i=0;i>u>>v>>w;
            G[u].push_back(make_pair(v,w)); //用make_pair()嵌入数据
            in[v]++;
        }
        topsort();
        int max1 = -1;
        for(int i=1;i<=n;i++)
            max1 = max(max1,d[i]); //d[i]里面的值已经存好了
        cout<

 

你可能感兴趣的:(STL)