結果

問題 No.812 Change of Class
ユーザー Bwambocos
提出日時 2019-04-12 22:13:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,303 bytes
コンパイル時間 1,882 ms
コンパイル使用メモリ 183,080 KB
実行使用メモリ 15,500 KB
最終ジャッジ日時 2024-06-12 19:06:43
合計ジャッジ時間 12,529 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 48
権限があれば一括ダウンロードができます

ソースコード

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