結果

問題 No.3660 LIS on Tree
コンテスト
ユーザー GOTKAKO
提出日時 2026-08-30 13:54:27
言語 C++17
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 88 ms / 2,000 ms
+ 365µs
コード長 739 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,366 ms
コンパイル使用メモリ 224,620 KB
実行使用メモリ 18,680 KB
最終ジャッジ日時 2026-08-30 13:54:39
合計ジャッジ時間 3,227 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int N; cin >> N;
    vector<int> S(N);
    for(auto &s : S) cin >> s;
    vector<pair<int,int>> V(N);
    for(int i=0; i<N; i++) V.at(i) = {S.at(i),i};
    sort(V.begin(),V.end());
    vector<vector<int>> Graph(N);
    for(int i=0; i<N-1; i++){
        int u,v; cin >> u >> v;
        u--; v--;
        Graph.at(u).push_back(v);
        Graph.at(v).push_back(u);
    }

    vector<long long> dp(N);
    for(auto [s,pos] : V){
        dp.at(pos) += s;
        for(auto to : Graph.at(pos)) if(S.at(pos) < S.at(to)) dp.at(to) = max(dp.at(to),dp.at(pos));
    }
    cout << *max_element(dp.begin(),dp.end()) << endl;
}
0