結果
問題 |
No.812 Change of Class
|
ユーザー |
|
提出日時 | 2020-04-14 20:02:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 175 ms / 4,000 ms |
コード長 | 1,098 bytes |
コンパイル時間 | 1,852 ms |
コンパイル使用メモリ | 176,364 KB |
実行使用メモリ | 9,408 KB |
最終ジャッジ日時 | 2024-10-01 18:07:41 |
合計ジャッジ時間 | 8,710 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 60 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using ll = long long ; using P = pair<int,int> ; const ll INF = 1e14; const int MOD = 1000000007; int main(){ int n,m; cin >> n >> m; vector<vector<int>> graph(n,vector<int>()); rep(i,m){ int a,b; cin >> a >> b; --a;--b; graph[a].push_back(b); graph[b].push_back(a); } int q; cin >> q; rep(_,q){ int a; cin >> a; --a; int cnt = 0; int d = 0; vector<int> day(n,-1); queue<int> q; q.push(a); day[a] = 0; while(!q.empty()){ int now = q.front(); if(now != a) cnt ++; q.pop(); for(int next:graph[now]){ if(day[next] >= 0 ) continue; day[next] = day[now] + 1; d = max(d,day[next]); q.push(next); } } int ans = 0; int res = 1; while(res < d) res *= 2,ans++; cout << cnt << " " << ans << endl; } }