結果

問題 No.812 Change of Class
ユーザー tekihei2317tekihei2317
提出日時 2019-04-12 23:11:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 4,000 ms
コード長 1,010 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 172,844 KB
実行使用メモリ 10,648 KB
最終ジャッジ日時 2023-09-03 14:07:52
合計ジャッジ時間 8,848 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
8,892 KB
testcase_01 AC 17 ms
6,160 KB
testcase_02 AC 54 ms
7,372 KB
testcase_03 AC 114 ms
9,516 KB
testcase_04 AC 100 ms
9,000 KB
testcase_05 AC 211 ms
9,860 KB
testcase_06 AC 179 ms
9,512 KB
testcase_07 AC 5 ms
5,980 KB
testcase_08 AC 4 ms
5,900 KB
testcase_09 AC 224 ms
10,312 KB
testcase_10 AC 211 ms
10,064 KB
testcase_11 AC 20 ms
7,248 KB
testcase_12 AC 134 ms
9,448 KB
testcase_13 AC 3 ms
5,728 KB
testcase_14 AC 4 ms
5,696 KB
testcase_15 AC 132 ms
8,540 KB
testcase_16 AC 11 ms
5,956 KB
testcase_17 AC 128 ms
8,760 KB
testcase_18 AC 92 ms
8,004 KB
testcase_19 AC 106 ms
8,556 KB
testcase_20 AC 220 ms
9,920 KB
testcase_21 AC 88 ms
7,908 KB
testcase_22 AC 41 ms
6,792 KB
testcase_23 AC 9 ms
5,872 KB
testcase_24 AC 14 ms
6,036 KB
testcase_25 AC 33 ms
6,528 KB
testcase_26 AC 170 ms
9,236 KB
testcase_27 AC 150 ms
8,964 KB
testcase_28 AC 103 ms
8,340 KB
testcase_29 AC 24 ms
6,232 KB
testcase_30 AC 131 ms
8,752 KB
testcase_31 AC 111 ms
8,248 KB
testcase_32 AC 52 ms
7,016 KB
testcase_33 AC 140 ms
9,184 KB
testcase_34 AC 12 ms
6,012 KB
testcase_35 AC 30 ms
6,456 KB
testcase_36 AC 13 ms
6,280 KB
testcase_37 AC 65 ms
7,176 KB
testcase_38 AC 9 ms
6,276 KB
testcase_39 AC 67 ms
7,420 KB
testcase_40 AC 19 ms
6,196 KB
testcase_41 AC 8 ms
6,140 KB
testcase_42 AC 139 ms
8,500 KB
testcase_43 AC 37 ms
7,836 KB
testcase_44 AC 94 ms
7,776 KB
testcase_45 AC 12 ms
6,276 KB
testcase_46 AC 34 ms
7,460 KB
testcase_47 AC 92 ms
7,856 KB
testcase_48 AC 107 ms
8,244 KB
testcase_49 AC 28 ms
6,392 KB
testcase_50 AC 4 ms
5,728 KB
testcase_51 AC 32 ms
6,708 KB
testcase_52 AC 65 ms
8,028 KB
testcase_53 AC 19 ms
6,148 KB
testcase_54 AC 17 ms
6,120 KB
testcase_55 AC 70 ms
9,028 KB
testcase_56 AC 81 ms
9,960 KB
testcase_57 AC 86 ms
10,184 KB
testcase_58 AC 46 ms
7,864 KB
testcase_59 AC 98 ms
10,648 KB
testcase_60 AC 4 ms
5,988 KB
testcase_61 AC 3 ms
5,688 KB
testcase_62 AC 4 ms
5,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

const int size=100010;
const int INF=1e9;
vint G[size];
int N,M;

int calc(int dist)
{
    if(dist==1) return 0;
    return calc((dist+1)/2)+1;
}

void bfs(int s)
{
    vint dist(N);
    REP(i,N) dist[i]=INF;
    dist[s]=0;
    queue<int> Q;
    Q.push(s);

    while(!Q.empty()){
	int v=Q.front(); Q.pop();
	for(int u:G[v]){
	    if(dist[u]!=INF) continue;
	    dist[u]=dist[v]+1;
	    Q.push(u);
	}
    }

    int cnt=0,day=0;
    REP(i,N){
	if(dist[i]!=INF and dist[i]>0){
	    cnt++;
	    int d=calc(dist[i]);
	    day=max(day,d);
	}
    }
    cout<<cnt<<' '<<day<<endl;
}

signed main()
{
    cin>>N>>M;
    REP(i,M){
	int a,b; cin>>a>>b;
	a--; b--;
	G[a].push_back(b);
	G[b].push_back(a);
    }

    int Q; cin>>Q;
    while(Q--){
	int q; cin>>q; q--;
	bfs(q);
    }
}


0