結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2019-04-13 09:38:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 630 ms / 4,000 ms |
| コード長 | 2,626 bytes |
| コンパイル時間 | 2,085 ms |
| コンパイル使用メモリ | 177,784 KB |
| 実行使用メモリ | 13,940 KB |
| 最終ジャッジ日時 | 2024-06-12 20:26:14 |
| 合計ジャッジ時間 | 14,675 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 60 |
ソースコード
#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);
}
}
はまやんはまやん