結果
問題 | No.812 Change of Class |
ユーザー | hamray |
提出日時 | 2020-11-13 18:33:31 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 134 ms / 4,000 ms |
コード長 | 3,336 bytes |
コンパイル時間 | 1,455 ms |
コンパイル使用メモリ | 156,608 KB |
実行使用メモリ | 10,176 KB |
最終ジャッジ日時 | 2023-09-30 02:16:37 |
合計ジャッジ時間 | 6,566 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
8,724 KB |
testcase_01 | AC | 9 ms
5,904 KB |
testcase_02 | AC | 27 ms
7,256 KB |
testcase_03 | AC | 55 ms
9,328 KB |
testcase_04 | AC | 50 ms
9,044 KB |
testcase_05 | AC | 133 ms
9,208 KB |
testcase_06 | AC | 111 ms
8,268 KB |
testcase_07 | AC | 6 ms
6,028 KB |
testcase_08 | AC | 3 ms
5,760 KB |
testcase_09 | AC | 126 ms
9,392 KB |
testcase_10 | AC | 134 ms
9,328 KB |
testcase_11 | AC | 16 ms
7,276 KB |
testcase_12 | AC | 84 ms
9,068 KB |
testcase_13 | AC | 3 ms
5,184 KB |
testcase_14 | AC | 4 ms
5,392 KB |
testcase_15 | AC | 86 ms
8,048 KB |
testcase_16 | AC | 8 ms
5,768 KB |
testcase_17 | AC | 79 ms
8,272 KB |
testcase_18 | AC | 60 ms
7,580 KB |
testcase_19 | AC | 68 ms
7,956 KB |
testcase_20 | AC | 133 ms
9,364 KB |
testcase_21 | AC | 60 ms
7,468 KB |
testcase_22 | AC | 28 ms
6,500 KB |
testcase_23 | AC | 7 ms
5,708 KB |
testcase_24 | AC | 10 ms
5,696 KB |
testcase_25 | AC | 23 ms
6,448 KB |
testcase_26 | AC | 108 ms
8,832 KB |
testcase_27 | AC | 97 ms
8,204 KB |
testcase_28 | AC | 67 ms
7,740 KB |
testcase_29 | AC | 18 ms
5,972 KB |
testcase_30 | AC | 87 ms
8,608 KB |
testcase_31 | AC | 74 ms
8,000 KB |
testcase_32 | AC | 33 ms
6,856 KB |
testcase_33 | AC | 91 ms
8,596 KB |
testcase_34 | AC | 9 ms
5,648 KB |
testcase_35 | AC | 18 ms
6,236 KB |
testcase_36 | AC | 9 ms
5,704 KB |
testcase_37 | AC | 42 ms
6,860 KB |
testcase_38 | AC | 8 ms
6,156 KB |
testcase_39 | AC | 45 ms
6,864 KB |
testcase_40 | AC | 13 ms
5,956 KB |
testcase_41 | AC | 7 ms
6,104 KB |
testcase_42 | AC | 89 ms
8,220 KB |
testcase_43 | AC | 23 ms
7,552 KB |
testcase_44 | AC | 62 ms
7,548 KB |
testcase_45 | AC | 9 ms
5,712 KB |
testcase_46 | AC | 20 ms
7,260 KB |
testcase_47 | AC | 61 ms
7,584 KB |
testcase_48 | AC | 68 ms
7,780 KB |
testcase_49 | AC | 19 ms
6,236 KB |
testcase_50 | AC | 4 ms
5,312 KB |
testcase_51 | AC | 21 ms
6,416 KB |
testcase_52 | AC | 41 ms
7,544 KB |
testcase_53 | AC | 14 ms
5,976 KB |
testcase_54 | AC | 11 ms
5,932 KB |
testcase_55 | AC | 34 ms
8,744 KB |
testcase_56 | AC | 38 ms
9,416 KB |
testcase_57 | AC | 41 ms
9,800 KB |
testcase_58 | AC | 23 ms
7,644 KB |
testcase_59 | AC | 46 ms
10,176 KB |
testcase_60 | AC | 3 ms
5,424 KB |
testcase_61 | AC | 4 ms
5,312 KB |
testcase_62 | AC | 4 ms
5,256 KB |
ソースコード
#include <bits/stdc++.h> //#include <atcoder/all> //using namespace atcoder; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") const double pi = 3.141592653589793238462643383279; using namespace std; //typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef pair<int, PII> TIII; typedef long long LL; typedef unsigned long long ULL; typedef vector<LL> VLL; typedef vector<VLL> VVLL; //container util //------------------------------------------ #define ALL(a) (a).begin(), (a).endf() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define SQ(a) ((a) * (a)) #define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).endf(); ++i) #define EXIST(s, e) ((s).find(e) != (s).endf()) #define SORT(c) sort((c).begin(), (c).endf()) //repetition //------------------------------------------ #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define REP(i, n) FOR(i, 0, n) #define MOD 1000000007 #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) const double EPS = 1e-4, PI = acos(-1); //ここから編集 typedef string::const_iterator State; struct UnionFind{ vector<int> par; vector<int> siz; UnionFind(int sz_): par(sz_), siz(sz_) { for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1; } void init(int sz_){ par.resize(sz_); siz.resize(sz_); for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1; } int root(int x){ if(x == par[x]) return x; return par[x] = root(par[x]); } bool merge(int x, int 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 issame(int x, int y){ return root(x) == root(y); } int size(int x){ return siz[root(x)]; } }; int N, M; int mx; int depth[101010]; vector<vector<int>> g(101010); int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cin >> N >> M; UnionFind uf(N); REP(i,M){ int p, q; cin >> p >> q; p--; q--; g[p].push_back(q); g[q].push_back(p); uf.merge(p, q); } int q; cin >> q; while(q--){ int a; cin >> a; mx = 0; a--; REP(i,N) depth[i] = -1; queue<int> q; q.push(a); depth[a] = 0; while(q.size()){ int v = q.front(); q.pop(); for(auto u: g[v]){ if(depth[u] == -1){ depth[u] = depth[v] + 1; q.push(u); } } } REP(i,N){ mx = max(mx, depth[i]); } if(mx == 0){ cout << uf.size(a)-1 << " " << 0 << endl; }else if(mx == 1){ cout << uf.size(a)-1 << " " << 0 << endl; }else{ mx--; int t=0; while(mx){ mx/=2; t++; } cout << uf.size(a)-1 << " " << t << endl; } } return 0; }