結果

問題 No.812 Change of Class
ユーザー 沙耶花沙耶花
提出日時 2020-12-08 15:03:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 397 ms / 4,000 ms
コード長 961 bytes
コンパイル時間 2,480 ms
コンパイル使用メモリ 211,564 KB
実行使用メモリ 14,888 KB
最終ジャッジ日時 2023-10-17 17:16:34
合計ジャッジ時間 12,943 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 184 ms
12,500 KB
testcase_01 AC 30 ms
4,912 KB
testcase_02 AC 100 ms
8,428 KB
testcase_03 AC 218 ms
13,976 KB
testcase_04 AC 190 ms
12,748 KB
testcase_05 AC 349 ms
12,824 KB
testcase_06 AC 265 ms
10,480 KB
testcase_07 AC 10 ms
5,176 KB
testcase_08 AC 5 ms
4,348 KB
testcase_09 AC 390 ms
14,356 KB
testcase_10 AC 378 ms
14,092 KB
testcase_11 AC 91 ms
10,100 KB
testcase_12 AC 306 ms
13,512 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 238 ms
10,276 KB
testcase_16 AC 18 ms
4,348 KB
testcase_17 AC 234 ms
10,916 KB
testcase_18 AC 169 ms
8,956 KB
testcase_19 AC 197 ms
9,832 KB
testcase_20 AC 397 ms
13,856 KB
testcase_21 AC 161 ms
8,728 KB
testcase_22 AC 74 ms
6,008 KB
testcase_23 AC 14 ms
4,348 KB
testcase_24 AC 23 ms
4,348 KB
testcase_25 AC 60 ms
5,344 KB
testcase_26 AC 321 ms
12,140 KB
testcase_27 AC 277 ms
11,324 KB
testcase_28 AC 201 ms
9,792 KB
testcase_29 AC 43 ms
4,884 KB
testcase_30 AC 248 ms
10,804 KB
testcase_31 AC 213 ms
9,616 KB
testcase_32 AC 96 ms
6,580 KB
testcase_33 AC 276 ms
11,752 KB
testcase_34 AC 21 ms
4,348 KB
testcase_35 AC 55 ms
5,524 KB
testcase_36 AC 20 ms
4,356 KB
testcase_37 AC 115 ms
7,176 KB
testcase_38 AC 31 ms
6,128 KB
testcase_39 AC 119 ms
7,172 KB
testcase_40 AC 35 ms
4,788 KB
testcase_41 AC 22 ms
5,828 KB
testcase_42 AC 241 ms
10,804 KB
testcase_43 AC 118 ms
9,100 KB
testcase_44 AC 164 ms
8,868 KB
testcase_45 AC 20 ms
4,352 KB
testcase_46 AC 114 ms
8,960 KB
testcase_47 AC 172 ms
8,692 KB
testcase_48 AC 207 ms
10,064 KB
testcase_49 AC 50 ms
5,260 KB
testcase_50 AC 4 ms
4,348 KB
testcase_51 AC 68 ms
6,052 KB
testcase_52 AC 149 ms
9,388 KB
testcase_53 AC 34 ms
4,752 KB
testcase_54 AC 29 ms
4,656 KB
testcase_55 AC 147 ms
11,508 KB
testcase_56 AC 173 ms
13,112 KB
testcase_57 AC 183 ms
13,572 KB
testcase_58 AC 96 ms
8,844 KB
testcase_59 AC 209 ms
14,888 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 #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

vector<int> bfs(vector<vector<int>> E,int start){
	vector<int> dis(E.size(),Inf);
	dis[start] = 0;
	queue<int> Q;
	Q.push(start);
	
	while(Q.size()>0){
		int u = Q.front();
		Q.pop();
		
		rep(i,E[u].size()){
			int v = E[u][i];
			if(dis[v]!=Inf)continue;
			dis[v] = dis[u]+1;
			Q.push(v);
		}
	}
	
	return dis;
}
	

int main(){

	int N,M;
	cin>>N>>M;
	
	vector<vector<int>> E(N,vector<int>());
	
	rep(i,M){
		int p,q;
		scanf("%d %d",&p,&q);
		p--;q--;
		E[p].push_back(q);
		E[q].push_back(p);
	}
	
	int Q;
	cin>>Q;
	
	rep(i,Q){
		int A;
		cin>>A;
		
		vector<int> ret = bfs(E,A-1);
		
		int ans = 0;
		int maxi = 0;
		rep(i,ret.size()){
			if(ret[i]==Inf)continue;
			ans++;
			maxi = max(maxi,ret[i]);
		}
		
		ans--;
		cout<<ans<<' ';
		ans = 0;
		while(maxi>1){
			ans++;
			maxi = (maxi+1)/2;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}
0