結果

問題 No.2427 Tree Distance Two
ユーザー にしろにしろ
提出日時 2023-10-30 12:27:18
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 794 ms / 2,000 ms
コード長 3,485 bytes
コンパイル時間 5,236 ms
コンパイル使用メモリ 316,840 KB
実行使用メモリ 29,048 KB
最終ジャッジ日時 2023-10-30 12:27:44
合計ジャッジ時間 23,944 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 794 ms
26,408 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 778 ms
26,408 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 682 ms
28,236 KB
testcase_08 AC 729 ms
29,048 KB
testcase_09 AC 691 ms
26,976 KB
testcase_10 AC 689 ms
27,464 KB
testcase_11 AC 713 ms
28,412 KB
testcase_12 AC 708 ms
26,452 KB
testcase_13 AC 745 ms
26,264 KB
testcase_14 AC 610 ms
24,560 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 17 ms
4,348 KB
testcase_21 AC 19 ms
4,348 KB
testcase_22 AC 6 ms
4,348 KB
testcase_23 AC 4 ms
4,348 KB
testcase_24 AC 16 ms
4,348 KB
testcase_25 AC 170 ms
9,452 KB
testcase_26 AC 453 ms
17,568 KB
testcase_27 AC 338 ms
13,676 KB
testcase_28 AC 703 ms
24,628 KB
testcase_29 AC 624 ms
21,988 KB
testcase_30 AC 416 ms
17,040 KB
testcase_31 AC 265 ms
12,356 KB
testcase_32 AC 461 ms
17,040 KB
testcase_33 AC 369 ms
15,456 KB
testcase_34 AC 107 ms
7,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
using ld = long double;
using st = string;
using mint = atcoder::modint998244353;
using Mint = atcoder::modint1000000007;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vs vector<string>
#define chmax(n,v) n=n<v?v:n
#define chmin(n,v) n=n>v?v:n
#define all(n) begin(n),end(n)
#define rev(n) reverse(all(n))
#define sor(n) stable_sort(all(n))
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rrep(i,a,n) for(ll i=a;i<(n);++i)
#define sz(n) n.size()
#define bit(n,shift) ((n&(1<<shift))!=0)
#define yn(x) cout << (x?"Yes":"No") << endl;
#define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin()
#define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin()
#define lb2(a,n) *lower_bound(a.begin(),a.end(),n)
#define ub2(a,n) *upper_bound(a.begin(),a.end(),n)
template <typename T> void input(T &a) { cin >> a; };
template <typename T1, typename... T2> void input(T1&a, T2 &...b) { cin >> a; input(b...); };
const ll inf = 1e18;

//std::setprecision(13); 出力桁を増やす
//2^29<10^9

ll di[8]={1,-1,0,0,1,1,-1,-1};
ll dj[8]={0,0,1,-1,1,-1,-1,1};
//ll da[4]={1,1,-1,-1};
//ll db[4]={1,-1,-1,1};
//ll na[4]={1,0,1,0};
//ll nb[4]={0,1,0,1};

template<typename T = ll>
vector<T> read(size_t n) {
  vector<T> ts(n);
  for (size_t i = 0; i < n; i++) cin >> ts[i];
  return ts;
}

bool is_prime(ll N) {
    if (N == 1) return false;
    for (ll i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int calc_digit(ll N){
    int res = 0;
    while(N>0){
        res++;
        N/=10;
    }
    return res;
}

ll factorial(ll n, ll mod = 1e18) {
    ll ans = 1;
    for(ll i = n; i >= 2; i--) ans = (ans * i) % mod;
    return ans;
}

void printl(vl v){
    ll vsz=v.size();
    for(ll i=0;i<vsz;i++){
        cout << v[i] << endl;
    }
}


void prints(vs v){
    ll vsz=v.size();
    for(ll i=0;i<vsz;i++){
        cout << v[i] << endl;
    }
}

ll round_up(ll x,ll y){
    return (x+y-1)/y;
}

bool in_out(ll x,ll y,ll h,ll w){
    return 0<=x and x<h and 0<=y and y<w;
}

struct UnionFind{
    vector<ll> par;
    vector<ll> size;
    
    UnionFind(ll n){
        par.resize(n+1,-1);
        size.resize(n+1,1);
    }

    ll root(ll x){
        if (par[x]==-1) return x;
        return par[x]=root(par[x]);
    }

    void unite(ll u,ll v){
        ll RootU=root(u),RootV=root(v);
        if(RootU==RootV){
            return;
        }
        if(size[RootU]<size[RootV]){
            par[RootU]=RootV;
            size[RootV]+=size[RootU];
        }else{
            par[RootV]=RootU;
            size[RootU]+=size[RootV];
        }
        return;
    }
};

vector<pair<ll, ll>> prime_factorize(ll N){
    vector<pair<ll, ll> > res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0;
        while (N % a == 0) {
            ex++;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(){
    
    ll n;
    cin >> n;

    vvl g(n);
    vl deg(n);

    rep(i,n-1){
        ll u,v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
        g[v].push_back(u);
        deg[u]++;
        deg[v]++;
    }

    vl vis(n,0);
    ll ans=0;

    rep(i,n){
        ll ans=0;
        for(ll j:g[i]){
            ans+=deg[j];
        }
        ans-=deg[i];
        cout << ans << endl;
    }

}
0