結果
| 問題 | No.3660 LIS on Tree |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-30 16:10:16 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 949 bytes |
| 記録 | |
| コンパイル時間 | 2,486 ms |
| コンパイル使用メモリ | 361,092 KB |
| 実行使用メモリ | 26,152 KB |
| 最終ジャッジ日時 | 2026-08-30 16:10:23 |
| 合計ジャッジ時間 | 6,914 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 TLE * 1 -- * 11 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
long long src(int x, vector<int> s, vector<vector<int>> m, vector<long long>& p) {
if(p.at(x) != -1) return p.at(x);
long long q=0;
for(int i=0; i<m.at(x).size(); i++) {
q = max(q, src(m.at(x).at(i), s, m, p));
}
p.at(x) = q+s.at(x);
return q+s.at(x);
}
int main() {
int n;
cin >> n;
vector<int> s(n);
vector<int> a(n-1), b(n-1);
for(int i=0; i<n; i++) cin >> s.at(i);
for(int i=0; i<n-1; i++) cin >> a.at(i) >> b.at(i);
vector<vector<int>> m(n);
for(int i=0; i<n-1; i++) {
if(s.at(a.at(i)-1) > s.at(b.at(i)-1)) m.at(b.at(i)-1).push_back(a.at(i)-1);
else if(s.at(a.at(i)-1) < s.at(b.at(i)-1)) m.at(a.at(i)-1).push_back(b.at(i)-1);
}
vector<long long> p(n, -1);
for(int i=0; i<n; i++) {
src(i, s, m, p);
}
long long ans=0;
for(int i=0; i<n; i++) ans = max(ans, p.at(i));
cout << ans;
}