結果

問題 No.812 Change of Class
ユーザー hamrayhamray
提出日時 2020-11-13 18:29:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,169 bytes
コンパイル時間 3,794 ms
コンパイル使用メモリ 152,504 KB
実行使用メモリ 13,788 KB
最終ジャッジ日時 2023-09-30 02:16:23
合計ジャッジ時間 10,837 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
12,528 KB
testcase_01 AC 11 ms
6,520 KB
testcase_02 AC 29 ms
9,604 KB
testcase_03 AC 64 ms
13,788 KB
testcase_04 AC 56 ms
12,808 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 5 ms
5,884 KB
testcase_08 AC 4 ms
5,736 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 13 ms
7,208 KB
testcase_12 WA -
testcase_13 AC 4 ms
5,324 KB
testcase_14 AC 4 ms
5,384 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 AC 20 ms
6,156 KB
testcase_36 AC 7 ms
5,556 KB
testcase_37 AC 48 ms
6,904 KB
testcase_38 AC 7 ms
6,220 KB
testcase_39 AC 48 ms
6,980 KB
testcase_40 AC 12 ms
5,996 KB
testcase_41 WA -
testcase_42 AC 110 ms
8,364 KB
testcase_43 AC 22 ms
7,404 KB
testcase_44 AC 71 ms
7,516 KB
testcase_45 AC 8 ms
5,740 KB
testcase_46 AC 21 ms
7,340 KB
testcase_47 AC 69 ms
7,520 KB
testcase_48 AC 81 ms
7,912 KB
testcase_49 AC 18 ms
6,196 KB
testcase_50 AC 4 ms
5,352 KB
testcase_51 WA -
testcase_52 AC 41 ms
7,468 KB
testcase_53 AC 14 ms
5,992 KB
testcase_54 AC 11 ms
5,816 KB
testcase_55 AC 28 ms
8,484 KB
testcase_56 AC 33 ms
8,920 KB
testcase_57 AC 35 ms
9,320 KB
testcase_58 AC 19 ms
7,492 KB
testcase_59 AC 38 ms
9,632 KB
testcase_60 AC 3 ms
5,412 KB
testcase_61 AC 2 ms
5,112 KB
testcase_62 AC 3 ms
5,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
void dfs(int v, int d, int p){
  depth[v] = d;
  mx = max(mx, d);
  for(auto u: g[v]){
    if(u != p && depth[u] == -1){
      dfs(u, d+1, v);
    }
  }
}
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;
      dfs(a, 0, -1);
      if(mx == 0){
        cout << 0 << " " << 0 << endl;
      }else if(mx == 1){
        cout << 1 << " " << 0 << endl; 
      }else{
        mx--;

        int t=0;
        while(mx){
          mx/=2;
          t++;
        }
        cout << uf.size(a)-1 << " " << t << endl;
      }
    }

    return 0;
}
0