結果

問題 No.812 Change of Class
ユーザー koyoprokoyopro
提出日時 2020-01-19 01:54:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,802 ms / 4,000 ms
コード長 1,676 bytes
コンパイル時間 2,994 ms
コンパイル使用メモリ 158,520 KB
実行使用メモリ 22,112 KB
最終ジャッジ日時 2023-09-03 16:29:38
合計ジャッジ時間 35,487 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 546 ms
19,028 KB
testcase_01 AC 53 ms
5,900 KB
testcase_02 AC 278 ms
11,992 KB
testcase_03 AC 642 ms
21,780 KB
testcase_04 AC 553 ms
19,780 KB
testcase_05 AC 1,802 ms
21,048 KB
testcase_06 AC 1,357 ms
18,932 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1,527 ms
22,112 KB
testcase_10 AC 1,637 ms
22,008 KB
testcase_11 AC 23 ms
7,936 KB
testcase_12 AC 935 ms
19,288 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 981 ms
15,380 KB
testcase_16 AC 25 ms
4,472 KB
testcase_17 AC 863 ms
16,376 KB
testcase_18 AC 561 ms
12,908 KB
testcase_19 AC 687 ms
14,384 KB
testcase_20 AC 1,724 ms
21,420 KB
testcase_21 AC 525 ms
12,476 KB
testcase_22 AC 152 ms
7,884 KB
testcase_23 AC 19 ms
4,420 KB
testcase_24 AC 33 ms
4,984 KB
testcase_25 AC 116 ms
6,856 KB
testcase_26 AC 1,340 ms
18,564 KB
testcase_27 AC 1,120 ms
16,860 KB
testcase_28 AC 678 ms
14,528 KB
testcase_29 AC 82 ms
5,908 KB
testcase_30 AC 983 ms
16,008 KB
testcase_31 AC 784 ms
13,868 KB
testcase_32 AC 218 ms
8,864 KB
testcase_33 AC 1,010 ms
17,604 KB
testcase_34 AC 31 ms
4,784 KB
testcase_35 AC 102 ms
6,840 KB
testcase_36 AC 40 ms
4,832 KB
testcase_37 AC 396 ms
9,872 KB
testcase_38 AC 8 ms
4,876 KB
testcase_39 AC 404 ms
10,084 KB
testcase_40 AC 59 ms
5,504 KB
testcase_41 AC 6 ms
4,428 KB
testcase_42 AC 1,199 ms
15,764 KB
testcase_43 AC 79 ms
10,992 KB
testcase_44 AC 721 ms
12,408 KB
testcase_45 AC 40 ms
4,664 KB
testcase_46 AC 67 ms
10,620 KB
testcase_47 AC 749 ms
12,772 KB
testcase_48 AC 775 ms
14,104 KB
testcase_49 AC 128 ms
6,580 KB
testcase_50 AC 5 ms
4,376 KB
testcase_51 AC 113 ms
7,588 KB
testcase_52 AC 302 ms
12,256 KB
testcase_53 AC 75 ms
5,528 KB
testcase_54 AC 64 ms
5,468 KB
testcase_55 AC 568 ms
16,572 KB
testcase_56 AC 680 ms
18,988 KB
testcase_57 AC 731 ms
19,864 KB
testcase_58 AC 342 ms
11,876 KB
testcase_59 AC 824 ms
22,028 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/

map<int, set<int>> F;
int N,M,Q,A;
int ans = 0, day=0;

void update(int a) {
    int D[N];
    REP(i,N)D[i]=LONG_LONG_MAX;
    D[a]=-1;
    queue<int> que;
    que.push(a);
    while(!que.empty()) {
        int b = que.front();
        que.pop();
        for (int c:F[b]) {
            int newd = D[b]+1;
            if (D[c]>newd) {
                D[c] = newd;
                que.push(c);
            }
        }
    }
    int ma = -1;
    ans = 0;
    REP(i,N) if (D[i]>=0 && D[i]<LONG_LONG_MAX){
        ma = max(ma, D[i]);
        ans++;
    }
    day = 0;
    while(ma >= (1<<day)) day++;
}

void solve() {
    cin>>N>>M;
    int p,q;
    REP(i,M) {
        cin>>p>>q;
        p--;
        q--;
        F[p].insert(q);
        F[q].insert(p);
    }
    cin>>Q;
    REP(_,Q) {
        cin>>A;
        update(--A);
        out("%lld %lld\n", ans, day);
    }
}
0