結果
問題 | No.1488 Max Score of the Tree |
ユーザー |
![]() |
提出日時 | 2021-04-06 13:12:10 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,410 bytes |
コンパイル時間 | 9,242 ms |
コンパイル使用メモリ | 292,384 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-01-03 01:00:16 |
合計ジャッジ時間 | 9,044 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 28 RE * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define ll long long #include "testlib.h" class UnionFind { public: vector < ll > par; vector < ll > siz; UnionFind(ll sz_) : par(sz_), siz(sz_, 1) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1); for (ll i = 0; i < sz_; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool same(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; int main(int argc, char* argv[]) { registerValidation(argc, argv); int n = inf.readInt(2, 100, "n"); inf.readSpace(); int k = inf.readInt(2, 100000, "k"); inf.readEoln(); UnionFind uf(n); map<pair<int, int>, int> mp; for(int i = 0; i < n-1; i++){ int a = inf.readInt(1, 100000, "a"); inf.readSpace(); int b = inf.readInt(1, 100000, "b"); inf.readSpace(); inf.readInt(1, k); inf.readEoln(); a--; b--; assert(a != b); int now = mp[{a, b}]; assert(now == 0); mp[{a, b}]++; assert(uf.same(a, b) == false); uf.unite(a, b); } inf.readEof(); }