結果

問題 No.1752 Up-Down Tree
ユーザー lgswdnlgswdn
提出日時 2024-03-06 22:25:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,771 bytes
コンパイル時間 2,354 ms
コンパイル使用メモリ 207,292 KB
実行使用メモリ 23,068 KB
最終ジャッジ日時 2024-03-06 22:26:00
合計ジャッジ時間 5,521 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
23,068 KB
testcase_01 AC 58 ms
23,068 KB
testcase_02 AC 44 ms
15,784 KB
testcase_03 AC 45 ms
15,784 KB
testcase_04 AC 63 ms
19,356 KB
testcase_05 AC 62 ms
20,688 KB
testcase_06 AC 56 ms
18,360 KB
testcase_07 AC 55 ms
18,360 KB
testcase_08 AC 31 ms
12,188 KB
testcase_09 AC 62 ms
15,004 KB
testcase_10 AC 17 ms
9,116 KB
testcase_11 AC 4 ms
9,116 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 4 ms
9,116 KB
testcase_21 AC 4 ms
9,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//Shirasu Azusa 2024.03
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} 
  return x*w;
}

const int N=1e5+5;
int n;
vi e[N];
priority_queue<int> q[N];

void dfs(int u,int fa) {
  for(int v:e[u]) if(v!=fa) {
    dfs(v,u);
    if(q[u].size()<q[v].size()) swap(q[u],q[v]);
    while(!q[v].empty()) q[u].push(q[v].top()), q[v].pop();
  }
  int sz=1;
  rep(t,0,1) if(q[u].size()) {
    int x=q[u].top(); q[u].pop(); sz+=x;
  } q[u].push(sz);
}

signed main() {
  n=read();
  rep(i,2,n) {
    int u=read(), v=read();
    e[u].eb(v), e[v].eb(u);
  }
  dfs(1,0);
  printf("%d\n",q[1].top());
  return 0;
}
0