結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
chocopuu
|
| 提出日時 | 2019-04-13 20:05:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 137 ms / 4,000 ms |
| コード長 | 1,687 bytes |
| コンパイル時間 | 1,510 ms |
| コンパイル使用メモリ | 175,560 KB |
| 実行使用メモリ | 12,220 KB |
| 最終ジャッジ日時 | 2024-06-12 20:34:55 |
| 合計ジャッジ時間 | 5,921 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 60 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const ll MOD=1000000007,INF=1e18;
int V,E,Q;
vint g[100010];
signed main() {
IOS();
cin>>V>>E;
vint p(E),q(E);
rep(i,0,E){
cin>>p[i]>>q[i];
p[i]--;q[i]--;
g[p[i]].pb(q[i]);
g[q[i]].pb(p[i]);
}
cin>>Q;
vint a(Q);
rep(i,0,Q){
cin>>a[i];
a[i]--;
queue<int>que;
vint dist(100010,INF);
dist[a[i]]=0;
que.push(a[i]);
int ma=0,ans=0;
while(!que.empty()){
int now=que.front();
que.pop();
ans++;
for(auto e:g[now]){
if(dist[e]!=INF)continue;
dist[e]=dist[now]+1;
chmax(ma,dist[e]);
que.push(e);
}
}
int tmp=1,cnt=0;
while(tmp<ma){tmp<<=1;cnt++;}
cout<<ans-1<<" "<<cnt<<endl;
}
return 0;
}
chocopuu