結果
問題 | No.812 Change of Class |
ユーザー | yuji9511 |
提出日時 | 2019-04-13 00:12:03 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,364 bytes |
コンパイル時間 | 1,223 ms |
コンパイル使用メモリ | 169,204 KB |
実行使用メモリ | 19,420 KB |
最終ジャッジ日時 | 2024-06-12 20:03:41 |
合計ジャッジ時間 | 22,395 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 113 ms
9,520 KB |
testcase_08 | AC | 33 ms
8,592 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 322 ms
12,360 KB |
testcase_12 | WA | - |
testcase_13 | AC | 7 ms
8,592 KB |
testcase_14 | AC | 6 ms
8,464 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | AC | 135 ms
9,888 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | AC | 121 ms
9,540 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | AC | 423 ms
14,920 KB |
testcase_56 | AC | 460 ms
18,692 KB |
testcase_57 | AC | 531 ms
18,588 KB |
testcase_58 | AC | 278 ms
13,288 KB |
testcase_59 | AC | 609 ms
19,420 KB |
testcase_60 | AC | 6 ms
8,592 KB |
testcase_61 | AC | 6 ms
8,464 KB |
testcase_62 | AC | 5 ms
8,592 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> lpair; const ll MOD = 1e9 + 7; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define print2(x,y) cout << (x) << " " << (y) << endl; #define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl; ll N,M; vector<ll> tree[100010]; // Union-Find struct UnionFind { private: ll N; vector<ll> parent; vector<ll> num; public: UnionFind(ll n){ N = n; rep(i,0,N) parent.push_back(i); rep(i,0,N) num.push_back(1); } ll root(ll x){ if(x == parent[x]) return x; else return parent[x] = root(parent[x]); } void unite(ll a, ll b){ a = root(a); b = root(b); if(a == b) return; parent[a] = b; ll sum = num[a] + num[b]; num[a] = sum; num[b] = sum; } bool same(ll a, ll b){ return root(a) == root(b);} ll sz(ll x){ return num[x];} }; int main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; UnionFind uf(100010); rep(i,0,M){ ll p,q; cin >> p >> q; p--; q--; tree[p].push_back(q); tree[q].push_back(p); uf.unite(p,q); } ll Q; cin >> Q; while(Q--){ ll A; cin >> A; A--; // print(uf.sz(uf.root(A)) - 1); priority_queue<lpair, vector<lpair> ,greater<lpair> > pq; ll dist[100010] = {}; rep(i,0,N) dist[i] = INF; dist[A] = 0; rep(i,0,N) pq.push(make_pair(dist[i], i)); while(!pq.empty()){ lpair l1 = pq.top(); pq.pop(); for(auto &e: tree[l1.second]){ if(dist[e] > dist[l1.second] + 1){ dist[e] = dist[l1.second] + 1; pq.push(make_pair(dist[e], e)); } } } // printa(dist, N); ll v = 0; rep(i,0,N){ if(dist[i] != INF) v = max(v, dist[i]); } ll ans = 0; if(v == 0 || v == 1){ ans = 0; }else if(v == 2){ ans = 1; }else{ ans = (v+1)/2; } cout << uf.sz(uf.root(A)) - 1 << " " << ans << endl; } }