結果

問題 No.812 Change of Class
ユーザー eQeeQe
提出日時 2019-04-12 22:47:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,100 bytes
コンパイル時間 3,040 ms
コンパイル使用メモリ 155,644 KB
実行使用メモリ 14,628 KB
最終ジャッジ日時 2023-09-03 13:52:42
合計ジャッジ時間 16,469 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 464 ms
11,140 KB
testcase_07 AC 7 ms
6,564 KB
testcase_08 AC 5 ms
6,072 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 24 ms
8,564 KB
testcase_12 WA -
testcase_13 AC 3 ms
5,876 KB
testcase_14 AC 3 ms
5,692 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 10 ms
6,988 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 10 ms
6,468 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 313 ms
11,580 KB
testcase_56 AC 402 ms
13,408 KB
testcase_57 AC 434 ms
13,932 KB
testcase_58 AC 205 ms
9,584 KB
testcase_59 AC 487 ms
14,628 KB
testcase_60 AC 3 ms
5,968 KB
testcase_61 AC 4 ms
6,044 KB
testcase_62 AC 3 ms
6,216 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]);
    }
    
    if(max==1)
      pt(uf.size(a)-1 << " " << 0);
    else if(max==2)
      pt(uf.size(a)-1 << " " << 1);
    else {
      ll t=0;
      while(max+4-pow(2, t+2)>pow(2, t+1)) t++;
      
      if(max+4-pow(2, t+2)<=0) t++;
      else t+=2;
      pt(uf.size(a)-1 << " " << t);
    }
  }
  
    
}





0