結果

問題 No.3385 Up Down Hiking (C++)
コンテスト
ユーザー tRue
提出日時 2025-11-18 22:22:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,108 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 204,892 KB
実行使用メモリ 16,208 KB
最終ジャッジ日時 2025-11-22 12:33:34
合計ジャッジ時間 8,974 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 25 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include"bits/stdc++.h"
using namespace std;

int main() {
    int n,m;
    cin>>n>>m;
    vector<int>h(n);
    vector<vector<int>>g(n);
    for(auto &x:h)cin>>x;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int>up(n,-n),down(n,-n);
    queue<int>que;
    que.push(0);
    int d=1;
    while(!que.empty()){
        int size=que.size();
        while(size--){
            int v=que.front();que.pop();
            up[v]=d;
            for(auto to:g[v])
                if(h[v]<h[to])
                    que.push(to);
        }
        d++;
    }
    que.push(n-1);
    d=1;
    while(!que.empty()){
        int size=que.size();
        while(size--){
            int v=que.front();que.pop();
            down[v]=d;
            for(auto to:g[v])
                if(h[v]<h[to])
                    que.push(to);
        }
        d++;
    }
    int k=-1,mid=-1;
    for(int i=0;i<n;i++){
        int len=up[i]+down[i]-1;
        if(len>k){
            k=len;mid=i;
        }
    }
    cout<<k<<endl;
    return 0;
}
0