結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
veqcc
|
| 提出日時 | 2019-04-12 22:36:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 411 ms / 4,000 ms |
| コード長 | 1,659 bytes |
| コンパイル時間 | 1,312 ms |
| コンパイル使用メモリ | 114,840 KB |
| 実行使用メモリ | 10,944 KB |
| 最終ジャッジ日時 | 2024-06-12 19:36:19 |
| 合計ジャッジ時間 | 11,145 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 60 |
ソースコード
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
typedef pair <int, int> P;
vector <int> edges[100005];
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int p, q;
cin >> p >> q;
p--; q--;
edges[p].push_back(q);
edges[q].push_back(p);
}
int Q;
cin >> Q;
for (int x = 0; x < Q; x++) {
int a;
cin >> a;
a--;
priority_queue <P, vector<P>, greater<P>> q;
q.push(P(0, a));
vector <bool> visited(n, false);
visited[a] = true;
vector <int> cost(n, 1e9);
cost[a] = 0;
while (q.size()) {
P cur = q.top();
q.pop();
int now = cur.second;
int c = cur.first;
if (cost[now] < c) continue;
for (int node : edges[now]) {
visited[node] = true;
if (cost[node] > c + 1) {
cost[node] = c + 1;
q.push(P(c+1, node));
}
}
}
int cnt = -1;
for (bool v : visited) if (v) cnt++;
int depth = 0;
for (int c : cost) if (c < 1e9) depth = max(depth, c);
int ret = 0;
while ((1 << ret) < depth) {
ret++;
}
cout << cnt << " " << ret << "\n";
}
return 0;
}
veqcc