結果

問題 No.812 Change of Class
ユーザー matsukin1111matsukin1111
提出日時 2019-04-22 23:28:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 4,000 ms
コード長 1,614 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 100,288 KB
実行使用メモリ 9,492 KB
最終ジャッジ日時 2023-09-03 15:14:24
合計ジャッジ時間 6,634 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
8,588 KB
testcase_01 AC 17 ms
6,544 KB
testcase_02 AC 42 ms
7,456 KB
testcase_03 AC 83 ms
9,080 KB
testcase_04 AC 73 ms
8,972 KB
testcase_05 AC 159 ms
8,840 KB
testcase_06 AC 141 ms
8,324 KB
testcase_07 AC 7 ms
6,400 KB
testcase_08 AC 7 ms
6,256 KB
testcase_09 AC 148 ms
9,016 KB
testcase_10 AC 143 ms
9,104 KB
testcase_11 AC 16 ms
6,872 KB
testcase_12 AC 95 ms
8,636 KB
testcase_13 AC 6 ms
6,380 KB
testcase_14 AC 7 ms
6,392 KB
testcase_15 AC 102 ms
7,944 KB
testcase_16 AC 13 ms
6,244 KB
testcase_17 AC 101 ms
8,104 KB
testcase_18 AC 79 ms
7,552 KB
testcase_19 AC 88 ms
7,792 KB
testcase_20 AC 151 ms
8,944 KB
testcase_21 AC 72 ms
7,488 KB
testcase_22 AC 35 ms
6,776 KB
testcase_23 AC 12 ms
6,244 KB
testcase_24 AC 15 ms
6,296 KB
testcase_25 AC 29 ms
6,708 KB
testcase_26 AC 126 ms
8,452 KB
testcase_27 AC 111 ms
8,132 KB
testcase_28 AC 82 ms
7,832 KB
testcase_29 AC 24 ms
6,616 KB
testcase_30 AC 106 ms
8,048 KB
testcase_31 AC 89 ms
7,936 KB
testcase_32 AC 43 ms
6,936 KB
testcase_33 AC 107 ms
8,316 KB
testcase_34 AC 14 ms
6,496 KB
testcase_35 AC 26 ms
6,616 KB
testcase_36 AC 14 ms
6,384 KB
testcase_37 AC 54 ms
7,144 KB
testcase_38 AC 10 ms
6,484 KB
testcase_39 AC 56 ms
7,220 KB
testcase_40 AC 18 ms
6,424 KB
testcase_41 AC 9 ms
6,324 KB
testcase_42 AC 109 ms
8,100 KB
testcase_43 AC 32 ms
7,396 KB
testcase_44 AC 74 ms
7,564 KB
testcase_45 AC 14 ms
6,280 KB
testcase_46 AC 31 ms
7,332 KB
testcase_47 AC 75 ms
7,796 KB
testcase_48 AC 83 ms
7,832 KB
testcase_49 AC 27 ms
6,696 KB
testcase_50 AC 7 ms
6,124 KB
testcase_51 AC 28 ms
6,736 KB
testcase_52 AC 51 ms
7,520 KB
testcase_53 AC 19 ms
6,512 KB
testcase_54 AC 17 ms
6,460 KB
testcase_55 AC 50 ms
8,272 KB
testcase_56 AC 58 ms
8,876 KB
testcase_57 AC 59 ms
8,984 KB
testcase_58 AC 33 ms
7,604 KB
testcase_59 AC 65 ms
9,492 KB
testcase_60 AC 4 ms
6,160 KB
testcase_61 AC 4 ms
6,104 KB
testcase_62 AC 4 ms
6,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };

vector<int>nxt[101010];
int dist[101010];

void bfs(int now) {
	queue<int>que;
	que.push(now);
	dist[now] = 0;

	while (que.size()) {
		int p = que.front();
		que.pop();
		fore(x, nxt[p]) {
			if (dist[x] == -1) {
				que.push(x);
				dist[x] = dist[p] + 1;
			}
		}
	}
}

int bindigit(int n) {
	int ret = 0;
	while (n > 0) {
		n /= 2;
		ret++;
	}
	return ret;
}


int main() {
	int n, m;
	cin >> n >> m;

	rep(i, 0, m) {
		int p, q;
		cin >> p >> q;
		p--, q--;
		nxt[p].pb(q);
		nxt[q].pb(p);
	}


	int q;
	cin >> q;
	rep(i, 0, q) {
		int a;
		cin >> a;
		a--;
		memset(dist,-1,sizeof(dist));
		bfs(a);
		int temp = 0;
		int cnt = 0;
		rep(i, 0, 101010) {
			temp = max(temp,dist[i]);
			if (dist[i] > 0)cnt++;
		}
		if (temp == 0) {
			cout << 0 << " " << 0 << endl;
		}
		else {
			cout << cnt << " " << bindigit(temp - 1) << endl;
		}
	}



	return 0;
}
0