結果

問題 No.812 Change of Class
ユーザー umezoumezo
提出日時 2022-08-13 05:39:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 662 ms / 4,000 ms
コード長 1,427 bytes
コンパイル時間 2,260 ms
コンパイル使用メモリ 214,032 KB
実行使用メモリ 13,892 KB
最終ジャッジ日時 2023-10-24 16:43:55
合計ジャッジ時間 17,053 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
9,512 KB
testcase_01 AC 13 ms
4,348 KB
testcase_02 AC 42 ms
6,700 KB
testcase_03 AC 92 ms
10,520 KB
testcase_04 AC 81 ms
9,716 KB
testcase_05 AC 662 ms
11,816 KB
testcase_06 AC 500 ms
11,100 KB
testcase_07 AC 5 ms
4,544 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 593 ms
12,052 KB
testcase_10 AC 628 ms
12,044 KB
testcase_11 AC 14 ms
7,112 KB
testcase_12 AC 352 ms
10,568 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 397 ms
9,156 KB
testcase_16 AC 19 ms
4,348 KB
testcase_17 AC 329 ms
9,532 KB
testcase_18 AC 229 ms
7,632 KB
testcase_19 AC 269 ms
8,488 KB
testcase_20 AC 653 ms
11,740 KB
testcase_21 AC 211 ms
7,436 KB
testcase_22 AC 87 ms
5,320 KB
testcase_23 AC 16 ms
4,348 KB
testcase_24 AC 24 ms
4,348 KB
testcase_25 AC 72 ms
4,916 KB
testcase_26 AC 511 ms
10,428 KB
testcase_27 AC 431 ms
9,656 KB
testcase_28 AC 272 ms
8,456 KB
testcase_29 AC 55 ms
4,556 KB
testcase_30 AC 353 ms
9,408 KB
testcase_31 AC 307 ms
8,284 KB
testcase_32 AC 114 ms
5,860 KB
testcase_33 AC 424 ms
10,060 KB
testcase_34 AC 21 ms
4,348 KB
testcase_35 AC 54 ms
4,648 KB
testcase_36 AC 25 ms
4,348 KB
testcase_37 AC 159 ms
5,992 KB
testcase_38 AC 6 ms
4,956 KB
testcase_39 AC 164 ms
6,116 KB
testcase_40 AC 34 ms
4,348 KB
testcase_41 AC 5 ms
4,740 KB
testcase_42 AC 442 ms
8,440 KB
testcase_43 AC 32 ms
6,856 KB
testcase_44 AC 259 ms
7,116 KB
testcase_45 AC 26 ms
4,348 KB
testcase_46 AC 28 ms
6,932 KB
testcase_47 AC 251 ms
7,140 KB
testcase_48 AC 271 ms
7,992 KB
testcase_49 AC 71 ms
4,544 KB
testcase_50 AC 5 ms
4,348 KB
testcase_51 AC 57 ms
4,976 KB
testcase_52 AC 111 ms
7,188 KB
testcase_53 AC 44 ms
4,348 KB
testcase_54 AC 40 ms
4,348 KB
testcase_55 AC 271 ms
10,424 KB
testcase_56 AC 338 ms
12,396 KB
testcase_57 AC 359 ms
13,024 KB
testcase_58 AC 175 ms
8,140 KB
testcase_59 AC 405 ms
13,892 KB
testcase_60 AC 2 ms
4,348 KB
testcase_61 AC 2 ms
4,348 KB
testcase_62 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const ll INF=1LL<<60;

struct Edge{
  int to;
  ll w;
  Edge(int to,ll w) : to(to),w(w) {}
};

using Graph=vector<vector<Edge>>;
using pli=pair<ll,int>;

template<class T> bool chmin(T& a,T b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}

Graph G;
vector<ll> dijkstra(int s){
  int n=G.size();
  vector<ll> dist(n,INF);
  dist[s]=0;
  
  priority_queue<pli,vector<pli>,greater<pli>> que;
  que.push({dist[s],s});
  
  while(!que.empty()){
    int v=que.top().second;
    ll d=que.top().first;
    que.pop();
    
    if(d>dist[v]) continue;
    
    for(auto e:G[v]){
      if(chmin(dist[e.to],dist[v]+e.w)){
        que.push({dist[e.to],e.to});
      }
    }
  }
  return dist;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n,m;
  cin>>n>>m;
  
  G.resize(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[a].push_back(Edge(b,1));
    G[b].push_back(Edge(a,1));
  }
  
  int q;
  cin>>q;
  while(q--){
    int a;
    cin>>a;
    a--;
    vector<ll> dis=dijkstra(a);
    ll cnt=0,ma=0;
    rep(i,n){
      if(i!=a && dis[i]!=INF){
        cnt++;
        ma=max(ma,dis[i]);
      }
    }
    ma--;
    int ans=0;
    while(ma>0){
      ans++;
      ma/=2;
    }
    cout<<cnt<<" "<<ans<<endl;
  }

  return 0;
}
0