結果

問題 No.812 Change of Class
ユーザー BwambocosBwambocos
提出日時 2019-04-12 22:55:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 692 ms / 4,000 ms
コード長 1,396 bytes
コンパイル時間 4,063 ms
コンパイル使用メモリ 179,552 KB
実行使用メモリ 15,088 KB
最終ジャッジ日時 2023-09-03 14:04:29
合計ジャッジ時間 18,922 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
10,364 KB
testcase_01 AC 21 ms
4,380 KB
testcase_02 AC 75 ms
7,028 KB
testcase_03 AC 162 ms
11,992 KB
testcase_04 AC 144 ms
10,728 KB
testcase_05 AC 678 ms
13,324 KB
testcase_06 AC 513 ms
12,400 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 598 ms
13,404 KB
testcase_10 AC 614 ms
13,460 KB
testcase_11 AC 19 ms
7,248 KB
testcase_12 AC 373 ms
11,740 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 434 ms
9,964 KB
testcase_16 AC 22 ms
4,376 KB
testcase_17 AC 412 ms
10,516 KB
testcase_18 AC 248 ms
8,476 KB
testcase_19 AC 323 ms
9,300 KB
testcase_20 AC 692 ms
13,244 KB
testcase_21 AC 234 ms
8,132 KB
testcase_22 AC 98 ms
5,564 KB
testcase_23 AC 17 ms
4,376 KB
testcase_24 AC 28 ms
4,380 KB
testcase_25 AC 78 ms
5,012 KB
testcase_26 AC 527 ms
11,696 KB
testcase_27 AC 464 ms
10,532 KB
testcase_28 AC 293 ms
9,316 KB
testcase_29 AC 60 ms
4,572 KB
testcase_30 AC 407 ms
10,292 KB
testcase_31 AC 367 ms
9,040 KB
testcase_32 AC 128 ms
6,176 KB
testcase_33 AC 423 ms
11,276 KB
testcase_34 AC 24 ms
4,376 KB
testcase_35 AC 64 ms
4,608 KB
testcase_36 AC 31 ms
4,376 KB
testcase_37 AC 186 ms
6,368 KB
testcase_38 AC 8 ms
4,712 KB
testcase_39 AC 202 ms
6,300 KB
testcase_40 AC 40 ms
4,380 KB
testcase_41 AC 6 ms
4,376 KB
testcase_42 AC 443 ms
9,408 KB
testcase_43 AC 44 ms
7,364 KB
testcase_44 AC 290 ms
7,792 KB
testcase_45 AC 30 ms
4,376 KB
testcase_46 AC 38 ms
7,028 KB
testcase_47 AC 292 ms
7,500 KB
testcase_48 AC 293 ms
8,568 KB
testcase_49 AC 80 ms
4,712 KB
testcase_50 AC 5 ms
4,376 KB
testcase_51 AC 65 ms
5,224 KB
testcase_52 AC 123 ms
7,880 KB
testcase_53 AC 51 ms
4,376 KB
testcase_54 AC 46 ms
4,376 KB
testcase_55 AC 329 ms
11,124 KB
testcase_56 AC 408 ms
13,328 KB
testcase_57 AC 438 ms
14,024 KB
testcase_58 AC 216 ms
8,660 KB
testcase_59 AC 495 ms
15,088 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, LL> P;
struct edge { LL to, cost; };

const LL inf = 1123456789;
std::vector<LL>dist;
std::vector<std::vector<edge>>G;

void dijkstra(LL s)
{
	std::priority_queue<P, std::vector<P>, std::greater<P>>que;
	std::fill(dist.begin(), dist.end(), inf);
	dist[s] = 0;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL v = p.second;
		if (dist[v] < p.first) continue;
		rep(i, G[v].size())
		{
			edge e = G[v][i];
			if (dist[e.to] > dist[v] + e.cost)
			{
				dist[e.to] = dist[v] + e.cost;
				que.push(P(dist[e.to], e.to));
			}
		}
	}
}

int main()
{
	LL N, M, Q;
	in >> N >> M;
	std::vector<LL>p(M), q(M);
	rep(i, M) in >> p[i] >> q[i];
	in >> Q;
	std::vector<LL>A(Q);
	rep(i, Q) in >> A[i];

	G.resize(N + 1);
	rep(i, M)
	{
		G[p[i]].push_back({ q[i],1 });
		G[q[i]].push_back({ p[i],1 });
	}
	rep(i, Q)
	{
		dist.clear();
		dist.resize(N + 1);
		dijkstra(A[i]);

		LL ans1 = 0, ans2 = 0;
		for (LL j = 1; j <= N; ++j)
		{
			if (A[i] == j) continue;
			if (dist[j] < inf)
			{
				++ans1;
				if (dist[j] > 1)
				{
					LL temp = dist[j] - 1, res = 0;
					while (temp > 0)
					{
						temp /= 2;
						++res;
					}
					ans2 = std::max(ans2, res);
				}
			}
		}
		out << ans1 << " " << ans2 << std::endl;
	}
}
0