結果
問題 | No.1607 Kth Maximum Card |
ユーザー | 👑 tute7627 |
提出日時 | 2021-04-09 19:06:12 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,875 bytes |
コンパイル時間 | 7,913 ms |
コンパイル使用メモリ | 331,612 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-06 07:48:57 |
合計ジャッジ時間 | 8,050 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
ソースコード
#include "testlib.h" #include<bits/stdc++.h> using namespace std; const int MIN_N = 2; const int MAX_N = 200000; const int MAX_M = 200000; const int MIN_K = 1; const int MAX_K = 200000; const int MIN_C = 1; const int MAX_C = 200000; namespace atcoder { // Implement (union by size) + (path compression) // Reference: // Zvi Galil and Giuseppe F. Italiano, // Data structures and algorithms for disjoint set union problems struct dsu { public: dsu() : _n(0) {} dsu(int n) : _n(n), parent_or_size(n, -1) {} int merge(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } std::vector<std::vector<int>> groups() { std::vector<int> leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } std::vector<std::vector<int>> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }), result.end()); return result; } private: int _n; // root node: -1 * component size // otherwise: parent std::vector<int> parent_or_size; }; } // namespace atcoder signed main(int argc,char* argv[]){ registerValidation(argc, argv); /*int N = inf.readInt(MIN_N, MAX_N, "N"); inf.readSpace(); int M = inf.readInt(N - 1, min<long long>(MAX_M, (long long)N * (N - 1) / 2), "M"); inf.readSpace(); inf.readInt(MIN_K, MAX_K, "K"); inf.readEoln(); set<pair<int, int>>st; atcoder::dsu uf(N); for(int i = 0; i < M; i++){ int u = inf.readInt(1, N - 1, "u"); inf.readSpace(); int v = inf.readInt(u + 1, N, "v"); inf.readSpace(); int c = inf.readInt(MIN_C, MAX_C, "c"); inf.ensuref(!st.count(make_pair(u, v)), "Multiple Edges"); uf.merge(u - 1, v - 1); st.emplace(u, v); inf.readEoln(); } inf.ensuref(uf.size(0) == N, "Connected");*/ inf.readEof(); return 0; }