結果

問題 No.812 Change of Class
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-04-13 09:38:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 577 ms / 4,000 ms
コード長 2,626 bytes
コンパイル時間 1,720 ms
コンパイル使用メモリ 175,404 KB
実行使用メモリ 13,624 KB
最終ジャッジ日時 2023-09-03 14:43:08
合計ジャッジ時間 16,441 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
8,752 KB
testcase_01 AC 16 ms
6,580 KB
testcase_02 AC 50 ms
7,372 KB
testcase_03 AC 106 ms
9,328 KB
testcase_04 AC 93 ms
8,828 KB
testcase_05 AC 577 ms
10,536 KB
testcase_06 AC 410 ms
10,112 KB
testcase_07 AC 5 ms
5,980 KB
testcase_08 AC 4 ms
6,032 KB
testcase_09 AC 546 ms
10,564 KB
testcase_10 AC 565 ms
10,552 KB
testcase_11 AC 15 ms
7,240 KB
testcase_12 AC 334 ms
9,940 KB
testcase_13 AC 3 ms
5,884 KB
testcase_14 AC 4 ms
5,952 KB
testcase_15 AC 340 ms
9,080 KB
testcase_16 AC 19 ms
6,104 KB
testcase_17 AC 324 ms
9,172 KB
testcase_18 AC 203 ms
8,124 KB
testcase_19 AC 238 ms
8,744 KB
testcase_20 AC 570 ms
10,448 KB
testcase_21 AC 192 ms
8,076 KB
testcase_22 AC 81 ms
6,964 KB
testcase_23 AC 16 ms
6,052 KB
testcase_24 AC 24 ms
6,188 KB
testcase_25 AC 67 ms
6,640 KB
testcase_26 AC 433 ms
9,780 KB
testcase_27 AC 369 ms
9,332 KB
testcase_28 AC 225 ms
8,756 KB
testcase_29 AC 52 ms
6,596 KB
testcase_30 AC 314 ms
9,144 KB
testcase_31 AC 266 ms
8,704 KB
testcase_32 AC 105 ms
7,132 KB
testcase_33 AC 339 ms
9,632 KB
testcase_34 AC 22 ms
6,164 KB
testcase_35 AC 55 ms
6,488 KB
testcase_36 AC 27 ms
6,316 KB
testcase_37 AC 151 ms
7,352 KB
testcase_38 AC 7 ms
6,284 KB
testcase_39 AC 155 ms
7,332 KB
testcase_40 AC 35 ms
6,408 KB
testcase_41 AC 6 ms
6,136 KB
testcase_42 AC 359 ms
8,624 KB
testcase_43 AC 31 ms
7,504 KB
testcase_44 AC 237 ms
7,792 KB
testcase_45 AC 27 ms
6,260 KB
testcase_46 AC 29 ms
7,480 KB
testcase_47 AC 244 ms
7,740 KB
testcase_48 AC 258 ms
8,076 KB
testcase_49 AC 70 ms
6,812 KB
testcase_50 AC 6 ms
5,900 KB
testcase_51 AC 55 ms
6,736 KB
testcase_52 AC 106 ms
7,824 KB
testcase_53 AC 44 ms
6,372 KB
testcase_54 AC 41 ms
6,432 KB
testcase_55 AC 293 ms
11,036 KB
testcase_56 AC 367 ms
12,536 KB
testcase_57 AC 389 ms
13,068 KB
testcase_58 AC 194 ms
9,224 KB
testcase_59 AC 439 ms
13,624 KB
testcase_60 AC 3 ms
5,876 KB
testcase_61 AC 4 ms
5,912 KB
testcase_62 AC 3 ms
5,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




int N, M;
vector<pair<int,int>> E[101010];
int Q;
//---------------------------------------------------------------------------------------------------
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
int vis[101010];
void dijk(int s, vector<ll>& D) {
	rep(i, 0, N) D[i] = infl;
	rep(i, 0, N) vis[i] = 0;

	min_priority_queue<pair<ll, int>> que;

	D[s] = 0;
	que.push({ 0, s });

	while (!que.empty()) {
		auto q = que.top(); que.pop();

		ll cst = q.first;
		int cu = q.second;

		if (vis[cu]) continue;
		vis[cu] = 1;

		fore(p, E[cu]) {
			ll cst2 = cst + p.second;
			int to = p.first;

			if (chmin(D[to], cst2)) que.push({ D[to], to });
		}
	}
}
//---------------------------------------------------------------------------------------------------
ll log2_roundup(ll x) {
	int res = 0;
	ll y = 1;
	while (y < x) {
		y *= 2;
		res++;
	}
	return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		E[a].push_back({ b,1 });
		E[b].push_back({ a,1 });
	}

	cin >> Q;
	vector<ll> d(N);
	rep(q, 0, Q) {
		int s; cin >> s; s--;

		dijk(s, d);

		int ans1 = 0;
		ll ans2 = 0;
		rep(i, 0, N) if (0 < d[i] and d[i] < infl) {
			ans1++;
			chmax(ans2, log2_roundup(d[i]));
		}

		printf("%d %lld\n", ans1, ans2);
	}
}
0