結果
| 問題 | No.3660 LIS on Tree |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-30 15:08:53 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 168 ms / 2,000 ms |
| + 930µs | |
| コード長 | 2,332 bytes |
| 記録 | |
| コンパイル時間 | 4,067 ms |
| コンパイル使用メモリ | 379,752 KB |
| 実行使用メモリ | 26,032 KB |
| 最終ジャッジ日時 | 2026-08-30 15:09:05 |
| 合計ジャッジ時間 | 7,461 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
//using mint = modint1000000007;
using ll = long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
template<typename T_>bool chmax(T_& a, const T_& b) { if (a < b) { a = b;return true; } else { return false; } }
template<typename T_>bool chmin(T_& a, const T_& b) { if (a > b) { a = b;return true; } else { return false; } }
#ifdef LOCAL
template<class T, class U> ostream& operator<<(ostream& o, const pair<T, U>& p) { return o << "(" << p.first << ", " << p.second << ")"; }
template<class... T> ostream& operator<<(ostream& o, const tuple<T...>& t) { o << "("; apply([&o](auto&&... a) { int c = 0; (((o << (c++ ? ", " : "") << a)), ...); }, t); return o << ")"; }
template<class V> auto operator<<(ostream& o, const V& v) -> std::enable_if_t<!std::is_same_v<V, std::string> && !std::is_same_v<V, std::string_view>, decltype(v.begin(), o)> { o << "{"; int c = 0; for (auto& x : v) o << (c++ ? ", " : "") << x; return o << "}"; }
#define dbg(...) cerr<<"["<<#__VA_ARGS__<<"]: ",([](auto&&... a){((cerr<<a<<' '),...);})(__VA_ARGS__),cerr<<'\n'
#else
#define dbg(...) void(0)
#endif
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,-1,0,1 };
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
void solve() {
int n;cin >> n;
vector<ll> s(n, 0);
priority_queue<P, vector<P>, greater<P>> pq;
vector<ll> d(n, 0);
for (int i = 0; i < n; i++) {
cin >> s[i];
pq.emplace(s[i], i);
d[i] = s[i];
}
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; i++) {
int u, v;cin >> u >> v;
u--;v--;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
while (pq.size()) {
auto [u, v] = pq.top();pq.pop();
if (d[v] != u)continue;
for (auto nx : g[v]) {
if (s[v] < s[nx]) {
if (chmax(d[nx], s[nx] + d[v])) {
pq.emplace(d[nx], nx);
}
}
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
chmax(ans, d[i]);
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}