Submission #63219733
Source Code Expand
// 期待外れでいたいだなんて
// いつから願ってしまった?
// 名も知れぬほうがいいなんて
// いつからか願ってしまった
// ココロもネジ巻出して
// 意味を失ってしまった
// 何ひとつも動かせない今日と
// 押しつぶすように広がる
// 澄んだ機械仕掛けの空
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// Pragmas
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// Namespaces
using namespace std;
using namespace __gnu_pbds;
// Data types
using si = short int;
using ll = long long;
using ull = unsigned long long;
using lll = __int128;
using ld = long double;
// Pairs
using pii = pair<int, int>;
using psi = pair<si, si>;
using pll = pair<ll, ll>;
using plll = pair<lll, lll>;
using pld = pair<ld, ld>;
#define fi first
#define se second
// PBDS
template<typename Z>
using ordered_set = tree<Z, null_type, less<Z>, rb_tree_tag, tree_order_statistics_node_update>;
// Various outputs and debug
template<typename Z, typename = void> struct is_iterable : false_type {};
template<typename Z> struct is_iterable<Z, void_t<decltype(begin(declval<Z>())),decltype(end(declval<Z>()))>> : true_type {};
template<typename Z> typename enable_if<is_iterable<Z>::value&&!is_same<Z, string>::value,ostream&>::type operator<<(ostream &os, const Z &v);
template<typename Y, typename Z> ostream& operator<<(ostream &os, const pair<Y, Z> &p) {
return os << "(" << p.fi << ", " << p.se << ")";
}
template<class TupType, size_t... I> void printTuple(ostream& os, const TupType& _tup, index_sequence<I...>) {
os << "(";
(..., (os << (I == 0? "" : ", ") << get<I>(_tup)));
os << ")";
}
template<class... Z> ostream& operator<<(ostream& os, const tuple<Z...>& _tup) {
printTuple(os, _tup, make_index_sequence<sizeof...(Z)>());
return os;
}
template<typename Z> typename enable_if<is_iterable<Z>::value&&!is_same<Z, string>::value,ostream&>::type operator<<(ostream &os, const Z &v) {
os << "[";
for (auto it = v.begin(); it != v.end();) { os << *it; if (++it != v.end()) os << ", "; }
return os << "]";
}
#define debug(...) logger(cout, #__VA_ARGS__, __VA_ARGS__)
#define debugV(v, x) vlogger(cout, #v, x, v[x]);
#define rrebug(...) logger(cerr, #__VA_ARGS__, __VA_ARGS__)
#define rrebugV(v, x) vlogger(cerr, #v, x, v[x]);
template <typename... Args>
void logger(ostream& os, string vars, Args &&...values) {
os << vars << " = "; string delim = "";
(..., (os << delim << values, delim = ", "));
os << "\n";
}
template<class Y, class Z>
void vlogger(ostream& os, string var, Y idx, Z val) {
os << var << "[" << idx << "] = " << val << "\n";
}
// Various macros
#define All(x) x.begin(), x.end()
#define Sort(x) sort(All(x))
#define Reverse(x) reverse(All(x))
#define Uniqueify(x) Sort(x); x.erase(unique(All(x)), x.end())
#define RandomSeed chrono::steady_clock::now().time_since_epoch().count()
#define MultipleTestcases int _tc; cin >> _tc; for (int _cur_tc = 1; _cur_tc <= _tc; _cur_tc++)
// Chmin & chmax
template<typename Z> bool chmin(Z &a, Z b) { return (b < a) ? a = b, true : false; }
template<typename Z> bool chmax(Z &a, Z b) { return (b > a) ? a = b, true : false; }
// Modular arithmetic
template<int MOD>
class ModInt {
public:
int v;
ModInt() : v(0) {}
ModInt(long long _v) {
v = int((-MOD < _v && _v < MOD) ? (_v) : (_v % MOD));
if (v < 0) v += MOD;
}
friend bool operator==(const ModInt &a, const ModInt &b) { return a.v == b.v; }
friend bool operator!=(const ModInt &a, const ModInt &b) { return a.v != b.v; }
friend bool operator< (const ModInt &a, const ModInt &b) { return a.v < b.v; }
friend bool operator<=(const ModInt &a, const ModInt &b) { return a.v <= b.v; }
friend bool operator> (const ModInt &a, const ModInt &b) { return a.v > b.v; }
friend bool operator>=(const ModInt &a, const ModInt &b) { return a.v >= b.v; }
ModInt &operator+=(const ModInt &a) { v = (long long)(v + a.v) % MOD; return *this; }
ModInt &operator-=(const ModInt &a) { v = (long long)(v - a.v + MOD) % MOD; return *this; }
ModInt &operator*=(const ModInt &a) { v = 1ll * v * a.v % MOD; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this) *= inverse(a); }
friend ModInt pow(ModInt a, long long x) {
ModInt res = 1;
for (; x; x /= 2, a *= a) if (x & 1) res *= a;
return res;
}
friend ModInt inverse(ModInt a) { return pow(a, MOD - 2); }
ModInt operator+ () const { return ModInt( v); }
ModInt operator- () const { return ModInt(-v); }
ModInt operator++() const { return *this += 1; }
ModInt operator--() const { return *this -= 1; }
friend ModInt operator+(ModInt a, const ModInt &b) { return a += b; }
friend ModInt operator-(ModInt a, const ModInt &b) { return a -= b; }
friend ModInt operator*(ModInt a, const ModInt &b) { return a *= b; }
friend ModInt operator/(ModInt a, const ModInt &b) { return a /= b; }
friend istream &operator>>(istream &is, ModInt &v) { return is >> v.v; }
friend ostream &operator<<(ostream &os, const ModInt &v) { return os << v.v; }
};
const int ModA = 998244353;
const int ModC = 1e9 + 7;
using MintA = ModInt<ModA>;
using MintC = ModInt<ModC>;
// Other constants
const ll INF = 1e18;
const ll iINF = 1e9;
const ld EPS = 1e-9;
const ld iEPS = 1e-6;
const int maxN = 200'023;
int n;
vector<int> adj[maxN];
int dp[maxN]; // take exactly 3, or just itself
int ans = -1;
void dfs(int cur, int par = -1) {
dp[cur] = 1;
vector<int> trans;
for (auto nxt : adj[cur]) if (nxt != par) {
dfs(nxt, cur);
trans.push_back(dp[nxt]);
}
if (trans.size() >= 3) {
sort(All(trans), greater<int>());
dp[cur] = trans[0] + trans[1] + trans[2] + 1;
if (par != -1) {
ans = max(ans, dp[cur] + 1);
}
if (trans.size() >= 4) {
ans = max(ans, trans[0] + trans[1] + trans[2] + trans[3] + 1);
}
}
// debugV(dp, cur);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n;
for (int u, v, i = 1; i < n; i++) {
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1);
cout << ans << "\n";
}
// dibisakan
Submission Info
Submission Time |
|
Task |
F - Alkane |
User |
Zanite |
Language |
C++ 20 (gcc 12.2) |
Score |
500 |
Code Size |
6742 Byte |
Status |
AC |
Exec Time |
86 ms |
Memory |
31428 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample00.txt, sample01.txt, sample02.txt |
All |
hand00.txt, hand01.txt, hand02.txt, hand03.txt, sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt, testcase37.txt, testcase38.txt, testcase39.txt, testcase40.txt, testcase41.txt, testcase42.txt, testcase43.txt, testcase44.txt, testcase45.txt, testcase46.txt, testcase47.txt, testcase48.txt, testcase49.txt, testcase50.txt, testcase51.txt |
Case Name |
Status |
Exec Time |
Memory |
hand00.txt |
AC |
2 ms |
3512 KiB |
hand01.txt |
AC |
2 ms |
3648 KiB |
hand02.txt |
AC |
2 ms |
3464 KiB |
hand03.txt |
AC |
2 ms |
3456 KiB |
sample00.txt |
AC |
1 ms |
3596 KiB |
sample01.txt |
AC |
2 ms |
3524 KiB |
sample02.txt |
AC |
1 ms |
3528 KiB |
testcase00.txt |
AC |
2 ms |
3644 KiB |
testcase01.txt |
AC |
2 ms |
3524 KiB |
testcase02.txt |
AC |
1 ms |
3416 KiB |
testcase03.txt |
AC |
2 ms |
3464 KiB |
testcase04.txt |
AC |
51 ms |
14248 KiB |
testcase05.txt |
AC |
54 ms |
15240 KiB |
testcase06.txt |
AC |
19 ms |
7872 KiB |
testcase07.txt |
AC |
54 ms |
15232 KiB |
testcase08.txt |
AC |
20 ms |
7816 KiB |
testcase09.txt |
AC |
55 ms |
15220 KiB |
testcase10.txt |
AC |
24 ms |
11568 KiB |
testcase11.txt |
AC |
60 ms |
23112 KiB |
testcase12.txt |
AC |
27 ms |
9660 KiB |
testcase13.txt |
AC |
54 ms |
15224 KiB |
testcase14.txt |
AC |
41 ms |
12908 KiB |
testcase15.txt |
AC |
60 ms |
15160 KiB |
testcase16.txt |
AC |
53 ms |
14464 KiB |
testcase17.txt |
AC |
79 ms |
15132 KiB |
testcase18.txt |
AC |
84 ms |
15112 KiB |
testcase19.txt |
AC |
85 ms |
15180 KiB |
testcase20.txt |
AC |
36 ms |
10372 KiB |
testcase21.txt |
AC |
58 ms |
15248 KiB |
testcase22.txt |
AC |
45 ms |
22604 KiB |
testcase23.txt |
AC |
76 ms |
31428 KiB |
testcase24.txt |
AC |
56 ms |
14684 KiB |
testcase25.txt |
AC |
80 ms |
15160 KiB |
testcase26.txt |
AC |
33 ms |
9924 KiB |
testcase27.txt |
AC |
86 ms |
15196 KiB |
testcase28.txt |
AC |
68 ms |
14624 KiB |
testcase29.txt |
AC |
73 ms |
15248 KiB |
testcase30.txt |
AC |
60 ms |
13856 KiB |
testcase31.txt |
AC |
78 ms |
15244 KiB |
testcase32.txt |
AC |
32 ms |
10020 KiB |
testcase33.txt |
AC |
76 ms |
15356 KiB |
testcase34.txt |
AC |
13 ms |
6304 KiB |
testcase35.txt |
AC |
68 ms |
15320 KiB |
testcase36.txt |
AC |
27 ms |
9476 KiB |
testcase37.txt |
AC |
58 ms |
15452 KiB |
testcase38.txt |
AC |
34 ms |
10904 KiB |
testcase39.txt |
AC |
58 ms |
15400 KiB |
testcase40.txt |
AC |
46 ms |
13364 KiB |
testcase41.txt |
AC |
57 ms |
15464 KiB |
testcase42.txt |
AC |
23 ms |
8920 KiB |
testcase43.txt |
AC |
57 ms |
15532 KiB |
testcase44.txt |
AC |
46 ms |
13412 KiB |
testcase45.txt |
AC |
57 ms |
15332 KiB |
testcase46.txt |
AC |
23 ms |
8492 KiB |
testcase47.txt |
AC |
58 ms |
15388 KiB |
testcase48.txt |
AC |
16 ms |
7216 KiB |
testcase49.txt |
AC |
57 ms |
15388 KiB |
testcase50.txt |
AC |
56 ms |
14912 KiB |
testcase51.txt |
AC |
56 ms |
15452 KiB |