結果

問題 No.812 Change of Class
ユーザー ShibuyapShibuyap
提出日時 2020-09-08 03:52:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,526 bytes
コンパイル時間 3,001 ms
コンパイル使用メモリ 206,280 KB
実行使用メモリ 12,904 KB
最終ジャッジ日時 2023-08-19 17:29:44
合計ジャッジ時間 9,799 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 6 ms
8,372 KB
testcase_08 AC 4 ms
8,200 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 4 ms
8,032 KB
testcase_14 AC 4 ms
8,048 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 7 ms
8,472 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 53 ms
11,440 KB
testcase_56 AC 61 ms
11,964 KB
testcase_57 AC 65 ms
12,168 KB
testcase_58 AC 35 ms
10,072 KB
testcase_59 AC 74 ms
12,704 KB
testcase_60 AC 4 ms
8,204 KB
testcase_61 AC 4 ms
8,052 KB
testcase_62 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}

struct edge{ int to, cost, id; };
const int INF = 1001001001;
const int MAX_N = 200005;

vector<edge> G[MAX_N];

int main() {
    int n, m;
    cin >> n >> m;
    rep(i,m){
        int from = 0, to = 0, cost = 1, id = i;;
        cin >> from >> to;
        from--; to--;
        edge e1, e2;
        e1.to = to;   e1.cost = cost; e1.cost = cost; e1.id = id;
        e2.to = from; e2.cost = cost; e2.cost = cost; e2.id = id;
        G[from].push_back(e1);
        G[to].push_back(e2);
    }

    int Q;
    cin >> Q;
    rep(_,Q){
        int a; cin >> a;
        a--;
        queue<int> que;
        que.push(a);
        int d[n] = {};
        int f[n] = {};
        f[a] = 1;
        while(que.size()>0){
            int x = que.front();
            que.pop();
            rep(i,G[x].size()){
                int y = G[x][i].to;
                if(f[y]) continue;
                d[y] = d[x]+1;
                f[y] = 1;
                que.push(y);
            }
        }
        int ans = -1;
        int ma = 0;
        rep(i,n){
            if(f[i]){
                ans++;
                ma = max(ma,d[i]);
            }
        }
        ma--;
        if(ma<0)ma++;
        cout << ans << ' ' << ma << endl;
    }

    return 0;
}

0