結果

問題 No.812 Change of Class
ユーザー leaf_1415leaf_1415
提出日時 2019-04-13 00:07:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 190 ms / 4,000 ms
コード長 943 bytes
コンパイル時間 861 ms
コンパイル使用メモリ 66,668 KB
実行使用メモリ 9,356 KB
最終ジャッジ日時 2023-09-03 14:16:53
合計ジャッジ時間 7,728 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
8,472 KB
testcase_01 AC 15 ms
6,080 KB
testcase_02 AC 43 ms
7,200 KB
testcase_03 AC 90 ms
9,088 KB
testcase_04 AC 79 ms
8,548 KB
testcase_05 AC 189 ms
8,616 KB
testcase_06 AC 159 ms
8,292 KB
testcase_07 AC 7 ms
6,016 KB
testcase_08 AC 5 ms
5,916 KB
testcase_09 AC 181 ms
8,892 KB
testcase_10 AC 189 ms
9,100 KB
testcase_11 AC 24 ms
6,840 KB
testcase_12 AC 149 ms
8,704 KB
testcase_13 AC 4 ms
5,728 KB
testcase_14 AC 3 ms
5,656 KB
testcase_15 AC 126 ms
7,828 KB
testcase_16 AC 11 ms
6,028 KB
testcase_17 AC 120 ms
7,984 KB
testcase_18 AC 91 ms
7,444 KB
testcase_19 AC 103 ms
7,708 KB
testcase_20 AC 190 ms
8,944 KB
testcase_21 AC 86 ms
7,252 KB
testcase_22 AC 40 ms
6,616 KB
testcase_23 AC 10 ms
5,964 KB
testcase_24 AC 13 ms
6,180 KB
testcase_25 AC 33 ms
6,464 KB
testcase_26 AC 156 ms
8,524 KB
testcase_27 AC 140 ms
8,056 KB
testcase_28 AC 100 ms
7,740 KB
testcase_29 AC 24 ms
6,216 KB
testcase_30 AC 126 ms
7,940 KB
testcase_31 AC 107 ms
7,616 KB
testcase_32 AC 50 ms
6,868 KB
testcase_33 AC 132 ms
8,216 KB
testcase_34 AC 12 ms
5,924 KB
testcase_35 AC 27 ms
6,376 KB
testcase_36 AC 12 ms
6,200 KB
testcase_37 AC 57 ms
6,884 KB
testcase_38 AC 10 ms
6,364 KB
testcase_39 AC 59 ms
6,952 KB
testcase_40 AC 18 ms
6,152 KB
testcase_41 AC 9 ms
6,080 KB
testcase_42 AC 123 ms
8,036 KB
testcase_43 AC 39 ms
7,252 KB
testcase_44 AC 83 ms
7,512 KB
testcase_45 AC 12 ms
6,200 KB
testcase_46 AC 36 ms
7,240 KB
testcase_47 AC 83 ms
7,376 KB
testcase_48 AC 99 ms
7,836 KB
testcase_49 AC 25 ms
6,440 KB
testcase_50 AC 5 ms
5,896 KB
testcase_51 AC 32 ms
6,472 KB
testcase_52 AC 69 ms
7,396 KB
testcase_53 AC 18 ms
6,104 KB
testcase_54 AC 16 ms
6,264 KB
testcase_55 AC 56 ms
8,200 KB
testcase_56 AC 62 ms
8,680 KB
testcase_57 AC 65 ms
8,916 KB
testcase_58 AC 35 ms
7,316 KB
testcase_59 AC 74 ms
9,356 KB
testcase_60 AC 4 ms
5,792 KB
testcase_61 AC 4 ms
5,932 KB
testcase_62 AC 4 ms
5,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#define inf 1000000000

using namespace std;

int n, m;
vector<int> G[100005];
int dist[100005];

void bfs(int s)
{
	dist[s] = 0;
	queue<int> Q;
	Q.push(s);
	
	int v;
	while(Q.size()){
		v = Q.front();
		Q.pop();
		for(int i = 0; i < G[v].size(); i++){
			if(dist[G[v][i]] < inf) continue;
			dist[G[v][i]] = dist[v] + 1;
			Q.push(G[v][i]);
		}
	}
}

int main(void)
{
	cin >> n >> m;
	int u, v;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	int Q, a;
	cin >> Q;
	for(int q = 0; q < Q; q++){
		cin >> a;
		for(int i = 1; i <= n; i++) dist[i] = inf;
		bfs(a);
		int cnt = 0, mx = 0;
		for(int i = 1; i <= n; i++) if(dist[i] < inf) cnt++;
		cout << cnt-1 << " ";
		for(int i = 1; i <= n; i++) if(dist[i] < inf) mx = max(mx, dist[i]);
		
		for(int i = 0; ; i++){
			if(mx <= (1<<i)){
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}
0