結果

問題 No.812 Change of Class
ユーザー 沙耶花沙耶花
提出日時 2020-12-08 15:00:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 936 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 211,776 KB
実行使用メモリ 14,868 KB
最終ジャッジ日時 2023-10-17 17:15:35
合計ジャッジ時間 16,039 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 10 ms
5,156 KB
testcase_08 AC 5 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 92 ms
10,080 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 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 31 ms
6,108 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
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 143 ms
11,488 KB
testcase_56 AC 170 ms
13,092 KB
testcase_57 AC 182 ms
13,552 KB
testcase_58 AC 94 ms
8,824 KB
testcase_59 AC 207 ms
14,868 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<<' ';
		if(ans==1)cout<<0<<endl;
		else cout<<(maxi+1)/2<<endl;
	}
	
	return 0;
}
0