結果

問題 No.812 Change of Class
ユーザー parukiparuki
提出日時 2019-04-28 20:50:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 4,000 ms
コード長 2,162 bytes
コンパイル時間 1,656 ms
コンパイル使用メモリ 176,364 KB
実行使用メモリ 10,352 KB
最終ジャッジ日時 2023-09-03 15:15:09
合計ジャッジ時間 7,105 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
7,872 KB
testcase_01 AC 9 ms
4,380 KB
testcase_02 AC 30 ms
5,656 KB
testcase_03 AC 63 ms
8,572 KB
testcase_04 AC 56 ms
8,008 KB
testcase_05 AC 155 ms
9,760 KB
testcase_06 AC 134 ms
9,348 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 135 ms
10,352 KB
testcase_10 AC 140 ms
10,316 KB
testcase_11 AC 11 ms
6,580 KB
testcase_12 AC 87 ms
9,432 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 94 ms
7,508 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 87 ms
8,212 KB
testcase_18 AC 68 ms
6,792 KB
testcase_19 AC 77 ms
7,264 KB
testcase_20 AC 144 ms
9,916 KB
testcase_21 AC 63 ms
6,488 KB
testcase_22 AC 28 ms
4,688 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 9 ms
4,376 KB
testcase_25 AC 24 ms
4,376 KB
testcase_26 AC 114 ms
8,920 KB
testcase_27 AC 106 ms
8,276 KB
testcase_28 AC 71 ms
7,220 KB
testcase_29 AC 19 ms
4,380 KB
testcase_30 AC 95 ms
8,000 KB
testcase_31 AC 84 ms
7,100 KB
testcase_32 AC 37 ms
5,356 KB
testcase_33 AC 100 ms
8,636 KB
testcase_34 AC 9 ms
4,376 KB
testcase_35 AC 21 ms
4,380 KB
testcase_36 AC 10 ms
4,380 KB
testcase_37 AC 55 ms
5,380 KB
testcase_38 AC 5 ms
4,668 KB
testcase_39 AC 56 ms
5,408 KB
testcase_40 AC 14 ms
4,376 KB
testcase_41 AC 5 ms
4,528 KB
testcase_42 AC 109 ms
7,480 KB
testcase_43 AC 20 ms
6,164 KB
testcase_44 AC 78 ms
6,200 KB
testcase_45 AC 10 ms
4,376 KB
testcase_46 AC 20 ms
6,216 KB
testcase_47 AC 77 ms
6,232 KB
testcase_48 AC 76 ms
6,952 KB
testcase_49 AC 23 ms
4,380 KB
testcase_50 AC 3 ms
4,376 KB
testcase_51 AC 22 ms
4,700 KB
testcase_52 AC 43 ms
6,484 KB
testcase_53 AC 16 ms
4,380 KB
testcase_54 AC 14 ms
4,376 KB
testcase_55 AC 42 ms
8,308 KB
testcase_56 AC 49 ms
9,052 KB
testcase_57 AC 52 ms
9,504 KB
testcase_58 AC 27 ms
6,420 KB
testcase_59 AC 57 ms
10,316 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

typedef int Weight;
struct Edge {
    int from, to;
    Weight wei;
    Edge(int from_, int to_, Weight wei_) :from(from_), to(to_), wei(wei_) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
const Weight INFW = numeric_limits<Weight>::max();

vector<Weight> bfs(Graph &G, int start) {
    vector<Weight> res(G.size(), -1);
    queue<pair<int, Weight> > Q;
    Q.push(make_pair(start, 0));
    while (Q.size()) {
        auto p = Q.front();
        Q.pop();
        if (res[p.first] != -1) continue;
        res[p.first] = p.second;
        for (auto &e : G[p.first])
            Q.push(make_pair(e.to, p.second + 1));
    }
    return res;
}

void solve() {
	// Q回BFS
    // 友達同士である距離は
    // 一日で2倍になる
    int N, M;
    cin >> N >> M;
    Graph G(N);
    rep(i, M) {
        int p, q;
        cin >> p >> q;
        --p; --q;
        G[p].emplace_back(p, q, 1);
        G[q].emplace_back(q, p, 1);
    }

    int Q;
    cin >> Q;
    rep(i, Q) {
        int A;
        cin >> A;
        --A;
        vi d = bfs(G, A);
        int friends = -1;
        int max_dis = 0;
        int day = 0;
        rep(j, N) {
            if (d[j] != -1) {
                friends++;
                smax(max_dis, d[j]);
            }
        }
        rep(j, 1 << 30) {
            if ((1 << j) >= max_dis) {
                day = j;
                break;
            }
        }
        cout << friends << ' ' << day << endl;
    }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0