結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2019-04-12 21:33:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 201 ms / 4,000 ms |
| コード長 | 1,019 bytes |
| コンパイル時間 | 2,388 ms |
| コンパイル使用メモリ | 202,800 KB |
| 最終ジャッジ日時 | 2025-01-07 01:42:59 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 60 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
struct FastIO{
FastIO(){
cin.tie(0);
ios::sync_with_stdio(0);
}
}fastio_beet;
//INSERT ABOVE HERE
signed main(){
Int n,m;
cin>>n>>m;
vector<vector<Int> > G(n);
for(Int i=0;i<m;i++){
Int x,y;
cin>>x>>y;
x--;y--;
G[x].emplace_back(y);
G[y].emplace_back(x);
}
Int q;
cin>>q;
while(q--){
Int s;
cin>>s;
s--;
Int cnt=0;
vector<Int> dist(n,-1);
queue<Int> q;
dist[s]=0;
q.emplace(s);
while(!q.empty()){
Int v=q.front();q.pop();
cnt++;
for(Int u:G[v]){
if(~dist[u]) continue;
dist[u]=dist[v]+1;
q.emplace(u);
}
}
Int d=*max_element(dist.begin(),dist.end());
Int ans=0;
while(d>(1<<ans)) ans++;
cout<<cnt-1<<" "<<ans<<endl;
}
return 0;
}
beet