結果

問題 No.2427 Tree Distance Two
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2023-08-18 22:23:22
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 3,301 bytes
コンパイル時間 1,789 ms
コンパイル使用メモリ 137,748 KB
実行使用メモリ 23,040 KB
最終ジャッジ日時 2024-05-06 04:38:17
合計ジャッジ時間 7,190 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 229 ms
21,120 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 239 ms
20,992 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 180 ms
21,856 KB
testcase_08 AC 199 ms
23,040 KB
testcase_09 AC 189 ms
22,016 KB
testcase_10 AC 201 ms
22,272 KB
testcase_11 AC 184 ms
21,764 KB
testcase_12 AC 196 ms
21,580 KB
testcase_13 AC 208 ms
21,404 KB
testcase_14 AC 112 ms
20,736 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 39 ms
7,808 KB
testcase_26 AC 122 ms
14,336 KB
testcase_27 AC 80 ms
11,392 KB
testcase_28 AC 211 ms
19,712 KB
testcase_29 AC 176 ms
17,792 KB
testcase_30 AC 117 ms
13,952 KB
testcase_31 AC 65 ms
10,240 KB
testcase_32 AC 117 ms
13,952 KB
testcase_33 AC 98 ms
12,672 KB
testcase_34 AC 25 ms
6,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <ostream>
#include <optional>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <ranges>
#include <map>
#include <unordered_map>
using namespace std;

#ifndef INCLUDED_MAIN
#define INCLUDED_MAIN
#include __FILE__



i32 main() {
    i64 n;
    cin >> n;
    vector g(n, vector<i32>());

    for (i32 _=0; _<n-1; _++) {
        i32 a, b;
        cin >> a >> b; a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<i32> ans(n, 0);
    for (i32 i=0; i<n; i++) {
        for (const auto& j : g[i]) {
            ans[j] += g[i].size() - 1;
        }
    }

    cout << ans;
}








/********************************************************************************/
#else

#ifdef ONLINE_JUDGE
#define debug(x) {}
#else
const int DEBUG_PRINT = 10;
const string bold = "\e[1m";
const string cyan = "\e[36m";
const string red = "\e[31m";
const string reset = "\e[0m";
#define debug(x) {cerr << bold << cyan << "[" << red << __LINE__ << cyan << "] "<< #x << ": " << reset; debgp(x); }
template<class T> void debgp(T &x) { cerr << x; }
template<class T, class U> void debgp(pair<T,U> &p) { cerr << "("; debgp(p.first); cerr << ", "; debgp(p.second); cerr << ")"; }
template<class T> void debgp(vector<T> &v) { cerr << "["; for (int i=0; i<min((int)v.size(), DEBUG_PRINT); i++) { debgp(v[i]); cerr << (i+1!=v.size()?" ":"]\n"); } if (v.size() > DEBUG_PRINT) cerr << " … ]\n"; }
template<class T> void debgp(vector<vector<T>> &v) {cerr<<"[\n"; for (int i=0; i<min((int)v.size(), DEBUG_PRINT); i++) { cerr<<" "; debgp(v[i]); } if (v.size() > DEBUG_PRINT) cerr<<" ︙\n"; ;  cerr << "]\n"; }
#endif


using i32 = int;
using i64 = long long;

const i64 INF = 0x0f0f'0f0f'0f0f'0f0f;

template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

vector dx4 = {1, 0, -1, 0};
vector dy4 = {0, 1, 0, -1};
vector dx8 = {1, 1, 0, -1, -1, -1, 0, 1};
vector dy8 = {0, 1, 1, 1, 0, -1, -1, -1};

template<class T, class U> istream& operator>>(istream&i,pair<T,U>&v){ i>>v.first>>v.second; return i; }
template<class T> istream& operator>>(istream&i,vector<T>&v){ for(T&e : v) i>>e; return i; }
template<class T, class U> ostream& operator<<(ostream &o, pair<T,U> &p){o<<"("<<p.first<<", "<<p.second<<")";return o; }
template<class T> ostream& operator<<(ostream&o,vector<T>&v){for(int i=0; i<v.size(); i++) { o << v[i] << (i+1!=v.size()?"\n":"\n");} return o;}

template<class T> optional<i32> position(vector<T>&v, T x) { auto it = std::find(v.begin(), v.end(), x); if (it == v.end()) return nullopt; return it - v.begin(); }
optional<i32> position(string &v, char x) { auto it = std::find(v.begin(), v.end(), x); if (it == v.end()) return nullopt; return it - v.begin(); }
template<class T> vector<pair<T, i32>> run_length_encoding(vector<T>&v) { vector<pair<T, i32>> res; if (v.empty()) return res; res.emplace_back(v[0], 0); for (const auto& x : v) { if (res.back().first == x) { res.back().second++; } else { res.emplace_back(x, 1); } } return res; }


struct init{init(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}init;
#endif
0