結果

問題 No.812 Change of Class
ユーザー tkmst201tkmst201
提出日時 2021-02-25 15:02:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 249 ms / 4,000 ms
コード長 1,405 bytes
コンパイル時間 2,607 ms
コンパイル使用メモリ 209,972 KB
実行使用メモリ 9,580 KB
最終ジャッジ日時 2024-04-08 12:25:51
合計ジャッジ時間 9,646 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
8,132 KB
testcase_01 AC 10 ms
6,676 KB
testcase_02 AC 30 ms
6,676 KB
testcase_03 AC 62 ms
8,904 KB
testcase_04 AC 55 ms
8,288 KB
testcase_05 AC 216 ms
8,400 KB
testcase_06 AC 159 ms
7,240 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 221 ms
9,104 KB
testcase_10 AC 235 ms
9,104 KB
testcase_11 AC 13 ms
7,036 KB
testcase_12 AC 128 ms
8,756 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 144 ms
7,148 KB
testcase_16 AC 8 ms
6,676 KB
testcase_17 AC 108 ms
7,408 KB
testcase_18 AC 88 ms
6,676 KB
testcase_19 AC 95 ms
6,740 KB
testcase_20 AC 249 ms
8,924 KB
testcase_21 AC 71 ms
6,676 KB
testcase_22 AC 31 ms
6,676 KB
testcase_23 AC 6 ms
6,676 KB
testcase_24 AC 9 ms
6,676 KB
testcase_25 AC 28 ms
6,676 KB
testcase_26 AC 167 ms
8,040 KB
testcase_27 AC 145 ms
7,504 KB
testcase_28 AC 91 ms
6,716 KB
testcase_29 AC 18 ms
6,676 KB
testcase_30 AC 123 ms
7,328 KB
testcase_31 AC 110 ms
6,676 KB
testcase_32 AC 40 ms
6,676 KB
testcase_33 AC 136 ms
7,784 KB
testcase_34 AC 10 ms
6,676 KB
testcase_35 AC 19 ms
6,676 KB
testcase_36 AC 8 ms
6,676 KB
testcase_37 AC 51 ms
6,676 KB
testcase_38 AC 5 ms
6,676 KB
testcase_39 AC 50 ms
6,676 KB
testcase_40 AC 12 ms
6,676 KB
testcase_41 AC 4 ms
6,676 KB
testcase_42 AC 134 ms
7,332 KB
testcase_43 AC 25 ms
6,676 KB
testcase_44 AC 80 ms
6,676 KB
testcase_45 AC 8 ms
6,676 KB
testcase_46 AC 21 ms
6,676 KB
testcase_47 AC 79 ms
6,676 KB
testcase_48 AC 87 ms
6,872 KB
testcase_49 AC 20 ms
6,676 KB
testcase_50 AC 2 ms
6,676 KB
testcase_51 AC 20 ms
6,676 KB
testcase_52 AC 52 ms
6,676 KB
testcase_53 AC 14 ms
6,676 KB
testcase_54 AC 11 ms
6,676 KB
testcase_55 AC 45 ms
7,844 KB
testcase_56 AC 57 ms
8,580 KB
testcase_57 AC 58 ms
8,932 KB
testcase_58 AC 29 ms
6,676 KB
testcase_59 AC 67 ms
9,580 KB
testcase_60 AC 2 ms
6,676 KB
testcase_61 AC 2 ms
6,676 KB
testcase_62 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> g(N);
	REP(i, M) {
		int p, q;
		scanf("%d %d", &p, &q);
		--p; --q;
		g[p].emplace_back(q);
		g[q].emplace_back(p);
	}
	
	auto func = [&](int st) -> pii {
		vector<int> dist(N, INF);
		queue<int> que;
		dist[st] = 0;
		que.emplace(st);
		int cnt = 0, mxd = 0;
		while (!que.empty()) {
			int u = que.front(); que.pop();
			++cnt;
			chmax(mxd, dist[u]);
			for (int v : g[u]) if (chmin(dist[v], dist[u] + 1)) que.emplace(v);
		}
		return {cnt, mxd};
	};
	
	int Q;
	cin >> Q;
	while (Q--) {
		int A;
		scanf("%d", &A);
		--A;
		auto [cnt, mxd] = func(A);
		--cnt;
		
		if (mxd <= 1) printf("%d %d\n", cnt, 0);
		else {
			for (int i = 16; i >= 0; --i) if ((mxd - 1) >> i & 1) {
				printf("%d %d\n", cnt, i + 1);
				break;
			}
		}
	}
}
0