結果

問題 No.812 Change of Class
ユーザー ahe100ahe100
提出日時 2019-04-12 22:26:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 4,000 ms
コード長 1,275 bytes
コンパイル時間 1,634 ms
コンパイル使用メモリ 173,396 KB
実行使用メモリ 14,492 KB
最終ジャッジ日時 2023-09-03 13:19:46
合計ジャッジ時間 8,104 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
12,684 KB
testcase_01 AC 15 ms
10,004 KB
testcase_02 AC 45 ms
11,212 KB
testcase_03 AC 90 ms
13,324 KB
testcase_04 AC 79 ms
12,720 KB
testcase_05 AC 198 ms
13,832 KB
testcase_06 AC 168 ms
12,984 KB
testcase_07 AC 9 ms
10,668 KB
testcase_08 AC 6 ms
9,952 KB
testcase_09 AC 190 ms
14,180 KB
testcase_10 AC 191 ms
14,108 KB
testcase_11 AC 29 ms
13,104 KB
testcase_12 AC 125 ms
13,436 KB
testcase_13 AC 5 ms
9,532 KB
testcase_14 AC 5 ms
9,576 KB
testcase_15 AC 126 ms
12,320 KB
testcase_16 AC 12 ms
9,724 KB
testcase_17 AC 118 ms
12,420 KB
testcase_18 AC 91 ms
11,716 KB
testcase_19 AC 102 ms
11,960 KB
testcase_20 AC 199 ms
13,940 KB
testcase_21 AC 85 ms
11,488 KB
testcase_22 AC 40 ms
10,536 KB
testcase_23 AC 11 ms
9,748 KB
testcase_24 AC 14 ms
9,908 KB
testcase_25 AC 33 ms
10,384 KB
testcase_26 AC 162 ms
12,956 KB
testcase_27 AC 137 ms
12,544 KB
testcase_28 AC 99 ms
11,896 KB
testcase_29 AC 25 ms
10,160 KB
testcase_30 AC 125 ms
12,324 KB
testcase_31 AC 107 ms
11,912 KB
testcase_32 AC 50 ms
10,664 KB
testcase_33 AC 135 ms
12,932 KB
testcase_34 AC 13 ms
9,812 KB
testcase_35 AC 27 ms
10,192 KB
testcase_36 AC 12 ms
9,808 KB
testcase_37 AC 60 ms
10,856 KB
testcase_38 AC 13 ms
11,036 KB
testcase_39 AC 62 ms
10,844 KB
testcase_40 AC 18 ms
10,040 KB
testcase_41 AC 11 ms
10,812 KB
testcase_42 AC 123 ms
12,036 KB
testcase_43 AC 42 ms
11,964 KB
testcase_44 AC 85 ms
11,772 KB
testcase_45 AC 13 ms
9,828 KB
testcase_46 AC 38 ms
11,948 KB
testcase_47 AC 86 ms
11,616 KB
testcase_48 AC 97 ms
12,008 KB
testcase_49 AC 27 ms
10,332 KB
testcase_50 AC 5 ms
9,588 KB
testcase_51 AC 31 ms
10,416 KB
testcase_52 AC 60 ms
11,792 KB
testcase_53 AC 20 ms
10,008 KB
testcase_54 AC 17 ms
10,020 KB
testcase_55 AC 60 ms
12,672 KB
testcase_56 AC 64 ms
13,636 KB
testcase_57 AC 68 ms
14,224 KB
testcase_58 AC 36 ms
11,572 KB
testcase_59 AC 75 ms
14,492 KB
testcase_60 AC 5 ms
9,764 KB
testcase_61 AC 4 ms
9,480 KB
testcase_62 AC 4 ms
9,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
日数:log(最長距離)
*/

ll n,m,Q,a[100010],g[100010],d[100010];
vector<ll> v[100010],c[100010];

void init(){
	cin>>n>>m;
	rep(i,m){
		ll x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	reg(i,1,n)g[i]=-1;
	reg(i,1,n)d[i]=1e18;
	cin>>Q;
	rep(i,Q)cin>>a[i];
}

int main(void){
	init();
	reg(i,1,n){
		if(g[i]==-1){
			g[i]=i;
			c[i].push_back(i);
			queue<ll> Q;
			Q.push(i);
			while(!Q.empty()){
				ll p = Q.front();Q.pop();
				for(ll q:v[p]){
					if(g[q]==-1){
						g[q]=i;
						Q.push(q);
						c[i].push_back(q);
					}
				}
			}
		}
	}
	rep(i,Q){
		//距離の最大値
		ll ans=0,ans2=0;
		rep(j,c[g[a[i]]].size()){
			d[c[g[a[i]]][j]]=1e18;
		}
		d[a[i]]=0;
		queue<ll> Q;
		Q.push(a[i]);
		while(!Q.empty()){
			ll p = Q.front();Q.pop();
			ans=max(ans,d[p]);
			for(ll q:v[p]){
				if(d[q]>d[p]+1){
					d[q]=d[p]+1;
					Q.push(q);
				}
			}
		}
		while(ans>(1<<ans2))ans2++;
		cout<<c[g[a[i]]].size()-1<<" "<<ans2<<endl;
	}
	return 0;
}
0