結果

問題 No.812 Change of Class
ユーザー tomatoma
提出日時 2019-04-12 22:16:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 200 ms / 4,000 ms
コード長 2,143 bytes
コンパイル時間 1,823 ms
コンパイル使用メモリ 175,736 KB
実行使用メモリ 9,900 KB
最終ジャッジ日時 2023-09-03 13:01:01
合計ジャッジ時間 8,876 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
8,444 KB
testcase_01 AC 14 ms
4,380 KB
testcase_02 AC 46 ms
5,912 KB
testcase_03 AC 98 ms
9,332 KB
testcase_04 AC 87 ms
8,624 KB
testcase_05 AC 193 ms
8,548 KB
testcase_06 AC 160 ms
7,220 KB
testcase_07 AC 7 ms
4,508 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 182 ms
9,604 KB
testcase_10 AC 185 ms
9,400 KB
testcase_11 AC 31 ms
7,276 KB
testcase_12 AC 146 ms
9,076 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 126 ms
7,268 KB
testcase_16 AC 9 ms
4,376 KB
testcase_17 AC 118 ms
7,780 KB
testcase_18 AC 91 ms
6,268 KB
testcase_19 AC 106 ms
6,744 KB
testcase_20 AC 200 ms
9,108 KB
testcase_21 AC 88 ms
6,164 KB
testcase_22 AC 39 ms
4,568 KB
testcase_23 AC 8 ms
4,380 KB
testcase_24 AC 11 ms
4,376 KB
testcase_25 AC 31 ms
4,392 KB
testcase_26 AC 152 ms
8,276 KB
testcase_27 AC 136 ms
7,640 KB
testcase_28 AC 100 ms
6,652 KB
testcase_29 AC 23 ms
4,380 KB
testcase_30 AC 123 ms
7,604 KB
testcase_31 AC 107 ms
6,764 KB
testcase_32 AC 49 ms
5,176 KB
testcase_33 AC 138 ms
8,000 KB
testcase_34 AC 11 ms
4,380 KB
testcase_35 AC 26 ms
4,412 KB
testcase_36 AC 10 ms
4,376 KB
testcase_37 AC 58 ms
5,296 KB
testcase_38 AC 13 ms
4,936 KB
testcase_39 AC 59 ms
5,148 KB
testcase_40 AC 17 ms
4,380 KB
testcase_41 AC 10 ms
4,672 KB
testcase_42 AC 123 ms
7,436 KB
testcase_43 AC 48 ms
6,440 KB
testcase_44 AC 82 ms
6,256 KB
testcase_45 AC 10 ms
4,380 KB
testcase_46 AC 46 ms
6,248 KB
testcase_47 AC 82 ms
6,240 KB
testcase_48 AC 98 ms
6,964 KB
testcase_49 AC 25 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 32 ms
4,596 KB
testcase_52 AC 69 ms
6,452 KB
testcase_53 AC 17 ms
4,380 KB
testcase_54 AC 14 ms
4,376 KB
testcase_55 AC 64 ms
7,980 KB
testcase_56 AC 75 ms
8,808 KB
testcase_57 AC 80 ms
9,332 KB
testcase_58 AC 42 ms
6,216 KB
testcase_59 AC 90 ms
9,900 KB
testcase_60 AC 1 ms
4,384 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



class UnionFind {
public:
	vector<int>rank, parent;
	//
	UnionFind(int size) {
		rank.resize(size, 0);
		parent.resize(size, 0);
		REP(i, size)parent[i] = i;
	}
	//؂̍߂
	int find(int x) {
		if (parent[x] == x)return x;
		else return parent[x] = find(parent[x]);
	}
	//xy̑W𕹍
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y])
			parent[x] = y;
		else {
			parent[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
	//xyWɑ邩ۂ
	bool same(int x, int y) {
		return (find(x) == find(y));
	}
};

int N, M, Q;
vector<vector<int>> edges;

int paint(int s) {
	vector<int> used(N, INF);
	queue<int> q;
	used[s] = 0;
	q.push(s);

	while (!q.empty()) {
		int now = q.front(); q.pop();
		int dist = used[now];
		for (auto next : edges[now]) {
			int nextdist = dist + 1;
			int befdist = used[next];
			if (nextdist >= befdist)continue;

			used[next] = nextdist;
			q.push(next);
		}
	}

	int res = 0;
	for (auto dist : used)if (dist != INF)res = max(res, dist);
	return res;
}

int count_day(int len) {
	int res = 0;
	while (len > 1) {
		len = (len / 2) + (len % 2 != 0 ? 1 : 0);
		res++;
	}
	return res;
}

int main()
{
	cin >> N >> M;
	edges.resize(N);
	UnionFind uf(N);

	REP(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
		uf.unite(a, b);
	}
	cin >> Q;
	REP(i, Q) {
		int A, cnt = 0;
		cin >> A;
		A--;
		REP(j, N)if (j != A && uf.same(A, j))cnt++;
		int len = paint(A);
		cout << cnt << " " << count_day(len) << endl;
	}
	cin >> N;
	return 0;
}
0