結果

問題 No.812 Change of Class
ユーザー eQeeQe
提出日時 2019-04-12 22:54:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 647 ms / 4,000 ms
コード長 1,894 bytes
コンパイル時間 1,310 ms
コンパイル使用メモリ 154,680 KB
実行使用メモリ 14,832 KB
最終ジャッジ日時 2023-09-03 13:59:29
合計ジャッジ時間 14,075 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
9,776 KB
testcase_01 AC 17 ms
6,860 KB
testcase_02 AC 53 ms
8,220 KB
testcase_03 AC 109 ms
10,436 KB
testcase_04 AC 97 ms
9,904 KB
testcase_05 AC 647 ms
11,868 KB
testcase_06 AC 457 ms
11,056 KB
testcase_07 AC 7 ms
6,548 KB
testcase_08 AC 5 ms
6,160 KB
testcase_09 AC 478 ms
12,068 KB
testcase_10 AC 495 ms
12,008 KB
testcase_11 AC 25 ms
8,584 KB
testcase_12 AC 273 ms
11,324 KB
testcase_13 AC 3 ms
5,812 KB
testcase_14 AC 4 ms
5,892 KB
testcase_15 AC 307 ms
9,988 KB
testcase_16 AC 19 ms
6,396 KB
testcase_17 AC 278 ms
10,360 KB
testcase_18 AC 209 ms
9,156 KB
testcase_19 AC 238 ms
9,676 KB
testcase_20 AC 510 ms
11,924 KB
testcase_21 AC 191 ms
8,932 KB
testcase_22 AC 82 ms
7,376 KB
testcase_23 AC 15 ms
6,392 KB
testcase_24 AC 24 ms
6,500 KB
testcase_25 AC 65 ms
7,104 KB
testcase_26 AC 394 ms
11,104 KB
testcase_27 AC 361 ms
10,392 KB
testcase_28 AC 245 ms
9,720 KB
testcase_29 AC 50 ms
6,892 KB
testcase_30 AC 315 ms
10,276 KB
testcase_31 AC 254 ms
9,648 KB
testcase_32 AC 103 ms
7,756 KB
testcase_33 AC 324 ms
10,688 KB
testcase_34 AC 21 ms
6,452 KB
testcase_35 AC 52 ms
6,964 KB
testcase_36 AC 24 ms
6,592 KB
testcase_37 AC 138 ms
7,836 KB
testcase_38 AC 11 ms
6,776 KB
testcase_39 AC 141 ms
8,208 KB
testcase_40 AC 33 ms
6,796 KB
testcase_41 AC 9 ms
6,788 KB
testcase_42 AC 291 ms
9,464 KB
testcase_43 AC 44 ms
8,452 KB
testcase_44 AC 205 ms
8,536 KB
testcase_45 AC 24 ms
6,592 KB
testcase_46 AC 41 ms
8,316 KB
testcase_47 AC 201 ms
8,596 KB
testcase_48 AC 209 ms
9,100 KB
testcase_49 AC 60 ms
7,028 KB
testcase_50 AC 6 ms
6,452 KB
testcase_51 AC 56 ms
7,188 KB
testcase_52 AC 107 ms
8,584 KB
testcase_53 AC 39 ms
6,700 KB
testcase_54 AC 35 ms
6,672 KB
testcase_55 AC 287 ms
11,844 KB
testcase_56 AC 358 ms
13,652 KB
testcase_57 AC 383 ms
14,024 KB
testcase_58 AC 188 ms
9,700 KB
testcase_59 AC 436 ms
14,832 KB
testcase_60 AC 3 ms
5,880 KB
testcase_61 AC 3 ms
5,848 KB
testcase_62 AC 4 ms
6,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;

class unionFind {
public:
  vector<ll> data;
  
  unionFind(ll size) {
    data.assign(size, -1);
  }
  
  bool same(ll x, ll y) {
    return find(x)==find(y);
  }
  
  void unite(ll x, ll y) {
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(data[x]>data[y]) swap(x, y);
    data[x]+=data[y];
    data[y]=x;
  }
  
  ll find(ll k) {
    if(data[k]<0) return k;
    return data[k]=find(data[k]);
  }
  
  ll size(ll k) {
    return -data[find(k)];
  }
  
};

ll N, M;
vector<ll> g[MAX];
ll d[MAX];

void dijkstra(ll s) {
  ll i, u;
  ll clr[MAX];
  for(i=0; i<N; i++) {
    d[i]=INF;
    clr[i]=0;
  }
  priority_queue<P> q;
  q.push(P(0, s));
  d[s]=0;
  
  while(q.size()) {
    P f=q.top(); q.pop();
    u=f.sc;
    
    clr[u]=1;
    if(d[u]<-f.ft) continue;
    
    for(i=0; i<g[u].size(); i++) {
      ll v=g[u][i];
      if(clr[v]==0 && d[v]>d[u]+1) {
        d[v]=d[u]+1;
        q.push(P(-d[v], v));
      }
    }
  }
}

int main(void) {
  cin >> N >> M;
  ll i, j;
  
  unionFind uf(N);
  
  for(i=0; i<M; i++) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    g[a].pb(b);
    g[b].pb(a);
    
    uf.unite(a, b);
    
  }
  
  ll Q;
  cin >> Q;
  for(i=0; i<Q; i++) {
    ll a;
    cin >> a;
    a--;
    
    dijkstra(a);
    ll max=1;
    for(j=0; j<N; j++) {
      if(j==a) continue;
      if(d[j]==INF) continue;
      chmax(max, d[j]);
    }
    
    ll t=0;
    while(max>pow(2, t)) t++;
    pt(uf.size(a)-1 << " " << t);
  }
  
    
}





0