結果

問題 No.812 Change of Class
ユーザー daut-dlangdaut-dlang
提出日時 2019-04-12 22:50:03
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 757 ms / 4,000 ms
コード長 2,050 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 97,588 KB
実行使用メモリ 25,368 KB
最終ジャッジ日時 2023-09-04 00:36:43
合計ジャッジ時間 14,010 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 631 ms
13,192 KB
testcase_01 AC 97 ms
11,276 KB
testcase_02 AC 336 ms
11,852 KB
testcase_03 AC 757 ms
12,740 KB
testcase_04 AC 655 ms
13,728 KB
testcase_05 AC 347 ms
25,252 KB
testcase_06 AC 292 ms
15,056 KB
testcase_07 AC 2 ms
5,916 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 325 ms
25,324 KB
testcase_10 AC 339 ms
25,368 KB
testcase_11 AC 22 ms
7,796 KB
testcase_12 AC 220 ms
25,272 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 241 ms
25,276 KB
testcase_16 AC 18 ms
6,156 KB
testcase_17 AC 215 ms
25,348 KB
testcase_18 AC 165 ms
15,080 KB
testcase_19 AC 192 ms
15,036 KB
testcase_20 AC 346 ms
25,308 KB
testcase_21 AC 155 ms
15,004 KB
testcase_22 AC 72 ms
11,188 KB
testcase_23 AC 15 ms
4,708 KB
testcase_24 AC 21 ms
5,216 KB
testcase_25 AC 57 ms
10,084 KB
testcase_26 AC 281 ms
25,268 KB
testcase_27 AC 247 ms
25,248 KB
testcase_28 AC 178 ms
20,956 KB
testcase_29 AC 44 ms
8,348 KB
testcase_30 AC 222 ms
15,200 KB
testcase_31 AC 193 ms
15,068 KB
testcase_32 AC 90 ms
11,948 KB
testcase_33 AC 242 ms
25,276 KB
testcase_34 AC 20 ms
5,912 KB
testcase_35 AC 52 ms
11,420 KB
testcase_36 AC 23 ms
4,640 KB
testcase_37 AC 127 ms
13,688 KB
testcase_38 AC 7 ms
6,744 KB
testcase_39 AC 131 ms
12,612 KB
testcase_40 AC 35 ms
10,576 KB
testcase_41 AC 5 ms
4,928 KB
testcase_42 AC 268 ms
25,272 KB
testcase_43 AC 51 ms
14,412 KB
testcase_44 AC 190 ms
14,724 KB
testcase_45 AC 24 ms
4,432 KB
testcase_46 AC 51 ms
13,948 KB
testcase_47 AC 193 ms
15,044 KB
testcase_48 AC 204 ms
15,064 KB
testcase_49 AC 55 ms
10,652 KB
testcase_50 AC 5 ms
4,380 KB
testcase_51 AC 56 ms
12,928 KB
testcase_52 AC 102 ms
14,260 KB
testcase_53 AC 41 ms
9,388 KB
testcase_54 AC 34 ms
10,120 KB
testcase_55 AC 165 ms
24,072 KB
testcase_56 AC 197 ms
25,124 KB
testcase_57 AC 211 ms
24,888 KB
testcase_58 AC 110 ms
20,128 KB
testcase_59 AC 236 ms
25,088 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{	
	auto N = RD;
	auto M = RD;
	auto edges = new long[][](N);
	foreach (i; 0..M)
	{
		auto p = RD-1;
		auto q = RD-1;
		edges[p] ~= q;
		edges[q] ~= p;
	}
	auto Q = RD;
	auto ans = new long[2][](Q);
	foreach (i; 0..Q)
	{
		auto a = RD-1;
		long[2][] open = [[a, 0]];
		auto used = new bool[](N);
		used[a] = true;
		long cnt, day;
		while (!open.empty)
		{
			auto n = open.front; open.popFront;
			auto j = n[0];
			auto d = n[1];
			++cnt;
			day = max(day, d);
			foreach (k; edges[j])
			{
				if (used[k]) continue;
				used[k] = true;
				open ~= [k, d+1];
			}
		}
		ans[i] = [cnt-1, day-1];
	}

	foreach (e; ans)
	{
		debug writeln("e[1]:", e[1]);
		auto d = e[1];
		long x = 1;
		long cnt;
		while (x <= d)
		{
			x *= 2;
			++cnt;
		}

		writeln(e[0], " ", e[0] == 0 ? 0 : cnt);
	}
	stdout.flush();
	debug readln();
}
0