結果

問題 No.812 Change of Class
ユーザー oxyshoweroxyshower
提出日時 2020-01-15 13:56:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,042 ms / 4,000 ms
コード長 1,348 bytes
コンパイル時間 1,698 ms
コンパイル使用メモリ 178,560 KB
実行使用メモリ 20,148 KB
最終ジャッジ日時 2023-09-03 16:03:47
合計ジャッジ時間 23,880 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 255 ms
15,008 KB
testcase_01 AC 39 ms
5,088 KB
testcase_02 AC 137 ms
9,736 KB
testcase_03 AC 301 ms
17,628 KB
testcase_04 AC 264 ms
15,264 KB
testcase_05 AC 962 ms
17,728 KB
testcase_06 AC 749 ms
15,944 KB
testcase_07 AC 10 ms
5,192 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 967 ms
18,524 KB
testcase_10 AC 954 ms
18,468 KB
testcase_11 AC 102 ms
10,172 KB
testcase_12 AC 636 ms
16,420 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 600 ms
13,008 KB
testcase_16 AC 30 ms
4,432 KB
testcase_17 AC 567 ms
13,904 KB
testcase_18 AC 379 ms
10,976 KB
testcase_19 AC 480 ms
12,680 KB
testcase_20 AC 1,042 ms
18,048 KB
testcase_21 AC 352 ms
10,708 KB
testcase_22 AC 144 ms
6,744 KB
testcase_23 AC 24 ms
4,380 KB
testcase_24 AC 38 ms
4,552 KB
testcase_25 AC 112 ms
5,976 KB
testcase_26 AC 789 ms
15,688 KB
testcase_27 AC 660 ms
14,052 KB
testcase_28 AC 444 ms
12,440 KB
testcase_29 AC 81 ms
5,144 KB
testcase_30 AC 626 ms
13,788 KB
testcase_31 AC 470 ms
11,980 KB
testcase_32 AC 183 ms
7,832 KB
testcase_33 AC 671 ms
14,924 KB
testcase_34 AC 35 ms
4,376 KB
testcase_35 AC 101 ms
5,692 KB
testcase_36 AC 40 ms
4,376 KB
testcase_37 AC 273 ms
8,072 KB
testcase_38 AC 32 ms
6,112 KB
testcase_39 AC 275 ms
8,124 KB
testcase_40 AC 61 ms
4,872 KB
testcase_41 AC 23 ms
5,356 KB
testcase_42 AC 699 ms
12,928 KB
testcase_43 AC 170 ms
9,868 KB
testcase_44 AC 436 ms
10,136 KB
testcase_45 AC 41 ms
4,380 KB
testcase_46 AC 157 ms
9,980 KB
testcase_47 AC 451 ms
10,120 KB
testcase_48 AC 586 ms
12,536 KB
testcase_49 AC 116 ms
5,560 KB
testcase_50 AC 6 ms
4,376 KB
testcase_51 AC 119 ms
6,384 KB
testcase_52 AC 298 ms
10,432 KB
testcase_53 AC 69 ms
4,860 KB
testcase_54 AC 63 ms
4,596 KB
testcase_55 AC 391 ms
14,724 KB
testcase_56 AC 517 ms
17,808 KB
testcase_57 AC 546 ms
18,636 KB
testcase_58 AC 274 ms
11,020 KB
testcase_59 AC 564 ms
20,148 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

struct edge{ int to,cost; };
vector<int> dikstra(int s,vector<vector<edge>> G){
  typedef pair<int, int> P;
  const int INF = 1LL << 60;

  priority_queue<P,vector<P>,greater<P>> que;
  vector<int> d(G.size(),INF); //sからの最短距離
  d[s] = 0;
  que.push({0,s}); //{最短距離,頂点}

  while( !que.empty() ){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push( {d[e.to],e.to} );
      }
    }
  }
  return d;
}

signed main(){

  int n, m; cin >> n >> m;
  vector<vector<edge>> G(n);
  for(int i = 0; i < m; i++){
    int s, t; cin >> s >> t;
    s--, t--;
    G[s].push_back({t, 1});
    G[t].push_back({s, 1});
  }

  int q; cin >> q;
  for(int i = 0; i < q; i++){
    int s; cin >> s;
    s--;
    auto dp = dikstra(s, G);
    int friends = 0, date = 0;
    for(int i = 0; i < n; i++){
      if(i != s && dp[i] != INF){
        friends++;
        date = max(date, dp[i]);
      }
    }
    int honsitu = 0, t = 1;
    while(t < date){
      honsitu++;
      t *= 2;
    }
    cout << friends << " " << honsitu << endl;
  }

  return 0;
}
0