結果

問題 No.812 Change of Class
ユーザー BwambocosBwambocos
提出日時 2019-04-12 22:13:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,303 bytes
コンパイル時間 1,877 ms
コンパイル使用メモリ 179,832 KB
実行使用メモリ 15,196 KB
最終ジャッジ日時 2023-09-03 13:14:31
合計ジャッジ時間 14,955 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 19 ms
7,376 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 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 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 8 ms
4,580 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 7 ms
4,376 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 257 ms
11,200 KB
testcase_56 AC 323 ms
13,344 KB
testcase_57 AC 343 ms
14,128 KB
testcase_58 AC 172 ms
8,512 KB
testcase_59 AC 392 ms
15,196 KB
testcase_60 AC 2 ms
4,376 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 = 112345678901234;
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) ans2 = std::max(ans2, dist[j] / 2 + dist[j] % 2);
			}
		}
		out << ans1 << " " << ans2 << std::endl;
	}
}
0