結果
| 問題 |
No.3206 う し た ウ ニ 木 あ く ん 笑
|
| コンテスト | |
| ユーザー |
AwashAmityOak
|
| 提出日時 | 2025-07-18 22:12:33 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 161 ms / 3,000 ms |
| コード長 | 3,349 bytes |
| コンパイル時間 | 5,751 ms |
| コンパイル使用メモリ | 334,332 KB |
| 実行使用メモリ | 87,588 KB |
| 最終ジャッジ日時 | 2025-07-18 22:12:43 |
| 合計ジャッジ時間 | 9,030 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
// g++ -Wall -std=gnu++20 -march=native -O2 -static -DAWASHAMITYOAK
#ifdef AWASHAMITYOAK
#include <procon_local.h>
#else
#include <bits/stdc++.h>
#include <atcoder/all>
#endif
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;
istream& operator>> (istream& is, mint& x) { long long _x; is >> _x; x = _x; return is; }
ostream& operator<< (ostream& os, const mint& x) { return os << x.val(); }
template<class T, class U>
ostream& operator<< (ostream& os, const pair<T, U>& x) { return os << "{" << x.first << ", " << x.second << "}"; }
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP2(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define REP1(i, n) REP2(i, 0, n)
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define RREP2(i, r, l) for (int i = (int)(r)-1; i >= (int)(l); --i)
#define RREP1(i, n) RREP2(i, n, 0)
#define rrep(...) OVERLOAD_REP(__VA_ARGS__, RREP2, RREP1)(__VA_ARGS__)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back
#define mp make_pair
#define mt make_tuple
const ll INF = 4e18;
const ll MOD = 998244353;
const ll MOD1 = 1e9 + 7;
template<class T> inline bool chmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template<class T> inline bool chmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<class T> T pow(T a, T b, T m) { return b ? b&1 ? a*pow(a, b^1, m)%m : pow(a*a%m, b>>1, m)%m : 1; }
template<class T> T pow(T a, T b) { return b ? b&1 ? pow(a, b^1)*a : pow(a*a, b>>1) : 1; }
template<class... T> inline void input(T&... a) { ((cin >> a), ...); }
template<class T, class... U> inline void print(const T& a, const U&... b) { cout << a; ((cout << " " << b), ...); }
template<class T, class... U> inline void println(const T& a, const U&... b) { print(a, b...); cout << endl; }
inline void println() { cout << endl; }
template<class T> inline void print(vector<T>& A) { rep(i, A.size()) if (i) print("", A[i]); else print(A[i]); }
template<class T> inline void println(vector<T>& A) { print(A); cout << endl; }
const int di[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dj[8] = {0, -1, 0, 1, -1, 1, -1, 1};
#define int ll
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
input(N);
vector<vector<int>> G(N);
rep(i, N-1) {
int u, v;
input(u, v);
--u; --v;
G[u].push_back(v);
G[v].push_back(u);
}
vector<int> memo(N, -1);
auto dist = [&](auto&& self, int i, int par) -> int {
if (memo[i] != -1) return memo[i];
memo[i] = 0;
for (auto j : G[i]) {
if (j == par) continue;
chmax(memo[i], self(self, j, i) + 1);
}
return memo[i];
};
int ans = 1;
auto dfs = [&](auto&& self, int i, int par, int l) -> void {
int d0 = l, d1 = 0;
vector<int> D = {l};
for (auto j : G[i]) {
if (j == par) continue;
D.push_back(dist(dist, j, i) + 1);
chmax(d1, dist(dist, j, i) + 1);
if (d0 < d1) swap(d0, d1);
}
sort(rall(D));
rep(i, D.size()) chmax(ans, D[i] * (i + 1) + 1);
for (auto j : G[i]) {
if (j == par) continue;
self(self, j, i, (dist(dist, j, i) + 1 == d0 ? d1 : d0) + 1);
}
};
dfs(dfs, 0, -1, 0);
println(ans);
}
AwashAmityOak