結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
peroon
|
| 提出日時 | 2019-04-17 13:48:06 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 148 ms / 4,000 ms |
| コード長 | 1,563 bytes |
| コンパイル時間 | 1,739 ms |
| コンパイル使用メモリ | 177,556 KB |
| 実行使用メモリ | 10,664 KB |
| 最終ジャッジ日時 | 2024-06-12 20:53:32 |
| 合計ジャッジ時間 | 6,317 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 60 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
const ll mod = 1e9 + 7;
const ll inf = 1e18;
vector<vector<ll> > G;
vector<ll> d;
pair<ll, ll> bfs(ll i){
fill(ALL(d), -1);
d[i] = 0;
queue<ll> que;
que.push(i);
pair<ll, ll> answer;
ll friend_num = 0;
ll longest_distance = 0;
while(!que.empty()){
ll a = que.front();
que.pop();
for(ll to : G[a]){
if(d[to]==-1){
d[to] = d[a]+1;
que.push(to);
friend_num++;
}
}
}
longest_distance = *max_element(ALL(d));
if(friend_num==0){
answer.first = 0;
answer.second = 0;
}
else{
ll days = ceil(log2(longest_distance));
answer.first = friend_num;
answer.second = days;
}
return answer;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// input
ll N, M;
cin >> N >> M;
G.resize(N+1);
d.resize(N+1);
FOR(i, 0, M){
ll p, q;
cin >> p >> q;
G[p].push_back(q);
G[q].push_back(p);
}
ll Q;
cin >> Q;
FOR(i, 0, Q){
ll a;
cin >> a;
auto p = bfs(a);
p2(p.first, p.second);
}
return 0;
}
peroon