結果

問題 No.3660 LIS on Tree
コンテスト
ユーザー Rumain831
提出日時 2026-08-31 09:39:54
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 174 ms / 2,000 ms
+ 155µs
コード長 684 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,140 ms
コンパイル使用メモリ 190,616 KB
実行使用メモリ 18,880 KB
最終ジャッジ日時 2026-08-31 09:40:07
合計ジャッジ時間 5,884 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
using P = pair<ll, int>;

int main(void){
  int n; cin >> n;
  vector<ll> s(n);
  vector<P> val;
  for(int i=0; i<n; i++){
    cin >> s[i];
    val.emplace_back(s[i], i);
  }
  sort(begin(val), end(val));
  vector<vector<int>> to(n);
  for(int i=0; i<n-1; i++){
    int a, b; cin >> a >> b; a--, b--;
    if(s[a]>s[b]) swap(a, b);
    if(s[a]<s[b]) to[a].push_back(b);
  }
  vector<ll> sum(n);
  for(int i=0; i<n; i++){
    auto [x, id]=val[i];
    sum[id]+=x;
    for(auto v:to[id]) sum[v]=max(sum[v], sum[id]);
  }
  cout << *max_element(begin(sum), end(sum)) << endl;
  return 0; 
}
0