結果

問題 No.812 Change of Class
ユーザー izumoizumo
提出日時 2019-04-12 23:25:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,333 bytes
コンパイル時間 1,825 ms
コンパイル使用メモリ 169,612 KB
実行使用メモリ 13,892 KB
最終ジャッジ日時 2023-09-03 14:11:02
合計ジャッジ時間 7,785 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
12,652 KB
testcase_01 AC 11 ms
7,080 KB
testcase_02 AC 30 ms
9,508 KB
testcase_03 AC 64 ms
13,892 KB
testcase_04 AC 55 ms
12,808 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 4 ms
6,300 KB
testcase_08 AC 4 ms
6,316 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 12 ms
7,788 KB
testcase_12 WA -
testcase_13 AC 4 ms
6,084 KB
testcase_14 AC 4 ms
6,052 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 AC 20 ms
6,840 KB
testcase_36 AC 9 ms
6,340 KB
testcase_37 AC 49 ms
7,260 KB
testcase_38 AC 6 ms
6,540 KB
testcase_39 AC 53 ms
7,236 KB
testcase_40 AC 13 ms
6,528 KB
testcase_41 AC 5 ms
6,440 KB
testcase_42 AC 110 ms
8,580 KB
testcase_43 AC 22 ms
7,976 KB
testcase_44 AC 74 ms
7,908 KB
testcase_45 AC 9 ms
6,484 KB
testcase_46 AC 21 ms
7,704 KB
testcase_47 AC 72 ms
7,888 KB
testcase_48 AC 84 ms
8,272 KB
testcase_49 AC 19 ms
6,692 KB
testcase_50 AC 4 ms
6,096 KB
testcase_51 AC 22 ms
7,124 KB
testcase_52 AC 45 ms
7,968 KB
testcase_53 AC 14 ms
6,540 KB
testcase_54 AC 11 ms
6,432 KB
testcase_55 AC 27 ms
8,632 KB
testcase_56 AC 32 ms
9,064 KB
testcase_57 AC 33 ms
9,408 KB
testcase_58 AC 19 ms
7,544 KB
testcase_59 AC 38 ms
9,628 KB
testcase_60 AC 4 ms
6,192 KB
testcase_61 AC 3 ms
6,088 KB
testcase_62 AC 4 ms
6,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

struct UnionFind{
	vi par;
	vi rank;

	UnionFind(int n=1){
		init(n);
	}

	// n要素で初期化
	void init(int n=1){
		par.resize(n);
		rank.resize(n);
		REP(i, n){
			par[i]=i;
			rank[i]=0;
		}
	}

	// xの根を求める
	int find(int x){
		if(par[x]==x){
			return x;
		}
		else{
			return par[x]=find(par[x]);
		}
	}

	// xとyが属する集合を併合
	bool unite(int x, int y){
		x=find(x);
		y=find(y);
		if(x==y){
			return false;
		}
		if(rank[x]<rank[y]){
			par[x]=y;
		}
		else{
			par[y]=x;
			if(rank[x]==rank[y]){
				++rank[x];
			}
		}
		return true;
	}

	// xとyが同じ集合に属するか判定
	bool issame(int x, int y){
		return find(x)==find(y);
	}
};

vi g[114514];
int sz[114514];
bool used[114514];

int dfs(int a, int cnt){
	int res=1;
	for(int x : g[a]){
		if(used[x]){
			continue;
		}
		used[x]=true;
		CHMAX(res, dfs(x, cnt+1)+1);
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, m, p, q, Q, a;
	cin>>n>>m;
	UnionFind uf(n);
	REP(i, m){
		cin>>p>>q;
		--p;
		--q;
		g[p].push_back(q);
		g[q].push_back(p);
		uf.unite(p, q);
	}
	REP(i, n){
		++sz[uf.find(i)];
	}
	cin>>Q;
	REP(i, Q){
		cin>>a;
		--a;
		if(sz[uf.find(a)]==1){
			cout<<0<<' '<<0<<'\n';
			continue;
		}
		REP(j, n){
			used[j]=false;
		}
		used[a]=true;
		// DEBUG(a);
		int res=dfs(a, 0)-1;
		// DEBUG(res);
		int ans=0, tmp=1;
		while(tmp<res){
			++ans;
			tmp*=2;
		}
		cout<<sz[uf.find(a)]-1<<' '<<ans<<'\n';
	}
	return 0;
}
0