結果

問題 No.812 Change of Class
ユーザー 👑 jupirojupiro
提出日時 2020-01-23 18:38:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 675 ms / 4,000 ms
コード長 2,147 bytes
コンパイル時間 1,385 ms
コンパイル使用メモリ 124,916 KB
実行使用メモリ 13,856 KB
最終ジャッジ日時 2023-09-03 16:12:03
合計ジャッジ時間 15,400 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
9,496 KB
testcase_01 AC 15 ms
4,380 KB
testcase_02 AC 49 ms
6,536 KB
testcase_03 AC 105 ms
10,428 KB
testcase_04 AC 93 ms
9,544 KB
testcase_05 AC 675 ms
11,776 KB
testcase_06 AC 528 ms
11,084 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 623 ms
11,964 KB
testcase_10 AC 623 ms
12,028 KB
testcase_11 AC 14 ms
7,144 KB
testcase_12 AC 352 ms
10,532 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 397 ms
9,120 KB
testcase_16 AC 18 ms
4,376 KB
testcase_17 AC 348 ms
9,476 KB
testcase_18 AC 231 ms
7,712 KB
testcase_19 AC 278 ms
8,332 KB
testcase_20 AC 621 ms
11,568 KB
testcase_21 AC 209 ms
7,536 KB
testcase_22 AC 85 ms
5,336 KB
testcase_23 AC 14 ms
4,380 KB
testcase_24 AC 24 ms
4,380 KB
testcase_25 AC 68 ms
4,932 KB
testcase_26 AC 479 ms
10,392 KB
testcase_27 AC 427 ms
9,624 KB
testcase_28 AC 254 ms
8,376 KB
testcase_29 AC 52 ms
4,516 KB
testcase_30 AC 386 ms
9,372 KB
testcase_31 AC 313 ms
8,248 KB
testcase_32 AC 109 ms
5,776 KB
testcase_33 AC 388 ms
9,964 KB
testcase_34 AC 21 ms
4,380 KB
testcase_35 AC 54 ms
4,484 KB
testcase_36 AC 25 ms
4,376 KB
testcase_37 AC 160 ms
6,008 KB
testcase_38 AC 6 ms
4,792 KB
testcase_39 AC 165 ms
5,964 KB
testcase_40 AC 34 ms
4,376 KB
testcase_41 AC 5 ms
4,572 KB
testcase_42 AC 440 ms
8,412 KB
testcase_43 AC 33 ms
6,840 KB
testcase_44 AC 296 ms
6,940 KB
testcase_45 AC 26 ms
4,376 KB
testcase_46 AC 28 ms
6,692 KB
testcase_47 AC 250 ms
6,976 KB
testcase_48 AC 297 ms
7,852 KB
testcase_49 AC 70 ms
4,548 KB
testcase_50 AC 4 ms
4,376 KB
testcase_51 AC 56 ms
4,896 KB
testcase_52 AC 116 ms
7,024 KB
testcase_53 AC 43 ms
4,376 KB
testcase_54 AC 39 ms
4,380 KB
testcase_55 AC 285 ms
10,292 KB
testcase_56 AC 357 ms
12,232 KB
testcase_57 AC 377 ms
12,868 KB
testcase_58 AC 190 ms
8,092 KB
testcase_59 AC 429 ms
13,856 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,380 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]);
		}
		ll res = 0;
		ll tmp = 1;
		while (tmp < time) {
			tmp *= 2;
			res++;
		}
		printf("%lld %lld\n", cnt - 1, res);
	}
	return 0;
}
0