結果

問題 No.812 Change of Class
ユーザー 👑 jupirojupiro
提出日時 2020-01-23 18:10:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,080 bytes
コンパイル時間 1,420 ms
コンパイル使用メモリ 126,432 KB
実行使用メモリ 13,736 KB
最終ジャッジ日時 2023-09-03 16:11:31
合計ジャッジ時間 16,738 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,392 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 13 ms
7,172 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 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 7 ms
4,932 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 5 ms
4,700 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 296 ms
10,568 KB
testcase_56 AC 368 ms
12,236 KB
testcase_57 AC 386 ms
12,992 KB
testcase_58 AC 191 ms
7,972 KB
testcase_59 AC 436 ms
13,736 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 <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

void dijkstra(ll start, vector<vector<pair<ll, ll>>>& graph, vector<ll>& dist) {
	dist[start] = 0;
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
	vector<bool> used(dist.size(), false);
	pq.push(make_pair(0, start));
	while (!pq.empty()) {
		ll d, node;
		tie(d, node) = pq.top();
		pq.pop();
		if (used[node]) continue;
		used[node] = true;
		for (pair<ll, ll> element : graph[node]) {
			ll new_d, new_node;
			tie(new_node, new_d) = element;
			new_d += d;
			if (new_d < dist[new_node]) {
				dist[new_node] = new_d;
				pq.push(make_pair(dist[new_node], new_node));
			}
		}
	}
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll n, m; scanf("%lld %lld", &n, &m);
	vector<vector<pair<ll, ll>>> g(n);
	for (ll i = 0; i < m; i++) {
		ll p, q; scanf("%lld %lld", &p, &q);
		p--; q--;
		g[p].emplace_back(q, 1);
		g[q].emplace_back(p, 1);
	}
	ll q; scanf("%lld", &q);
	while (q--) {
		ll a; scanf("%lld", &a);
		a--;
		vector<ll> d(n, INF);
		d[a] = 0;
		dijkstra(a, g, d);
		ll cnt = 0;
		ll time = 0;
		for (ll i = 0; i < n; i++) {
			if (d[i] == INF) continue;
			cnt++;
			if (d[i] > 1) chmax(time, (d[i] + 1) / 2);
		}
		printf("%lld %lld\n", cnt - 1, time);
	}
	return 0;
}
0