結果

問題 No.812 Change of Class
ユーザー mamekin
提出日時 2019-04-15 23:04:42
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 211 ms / 4,000 ms
コード長 1,652 bytes
コンパイル時間 1,408 ms
コンパイル使用メモリ 126,112 KB
実行使用メモリ 9,028 KB
最終ジャッジ日時 2024-06-12 20:51:53
合計ジャッジ時間 7,237 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;
pair<int, int> solve(const vector<vector<int> >& edges, int a)
{
int n = edges.size();
vector<bool> isUsed(n, false);
queue<int> q;
isUsed[a] = true;
q.push(a);
int len = -1;
int cnt = 0;
while(!q.empty()){
++ len;
int m = q.size();
while(--m >= 0){
int x = q.front();
q.pop();
for(int y : edges[x]){
if(!isUsed[y]){
isUsed[y] = true;
q.push(y);
++ cnt;
}
}
}
}
int day = 0;
while(len > 1){
++ day;
len = (len + 1) / 2;
}
return make_pair(cnt, day);
}
int main()
{
int n, m;
cin >> n >> m;
vector<vector<int> > edges(n);
for(int i=0; i<m; ++i){
int p, q;
cin >> p >> q;
-- p;
-- q;
edges[p].push_back(q);
edges[q].push_back(p);
}
int q;
cin >> q;
while(--q >= 0){
int a;
cin >> a;
-- a;
auto ans = solve(edges, a);
cout << ans.first << ' ' << ans.second << endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0