結果

問題 No.812 Change of Class
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-04-17 13:11:24
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,603 bytes
コンパイル時間 2,757 ms
コンパイル使用メモリ 85,756 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2023-09-03 15:10:33
合計ジャッジ時間 7,638 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 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 3 ms
4,380 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 78 ms
7,420 KB
testcase_56 AC 88 ms
8,184 KB
testcase_57 AC 92 ms
8,484 KB
testcase_58 AC 50 ms
5,836 KB
testcase_59 AC 101 ms
9,344 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 1 ms
4,376 KB
testcase_62 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int, int>

#define MOD 1000000007
#define INF 2147483647
#define NINF (-2147483647-1)
#define LLINF 9223372036854775807
using ll = long long;
using namespace std;

struct edge {
    int to;
    edge(int to) :to(to){}
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<edge>> G(N,vector<edge>());
    for (int i = 0; i < M; i++)
    {
        int p, q;
        cin >> p >> q;
        p--; q--;
        G[p].push_back(edge(q));
        G[q].push_back(edge(p));
    }
    int Q;
    cin >> Q;
    vector<bool> visited(N);
    vector<P> ans(Q);
    for (int i = 0; i < Q; i++)
    {
        int a, m = -1, cnt = -1;
        cin >> a;
        a--;
        queue<P> que;
        fill(visited.begin(), visited.end(), false);
        que.push(P(a,0));
        while (!que.empty()) {
            P p = que.front(); que.pop();
            if (visited[p.first]) continue;
            visited[p.first] = true;
            cnt++;
            for (int j = 0; j < G[p.first].size(); j++)
            {
                que.push(P(G[p.first][j].to, p.second + 1));
            }
            m = max(m, p.second);
        }
        ans[i].first = cnt;
        ans[i].second = max(0,m-1);
    }
    for (int i = 0; i < Q; i++)
    {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    getchar(); getchar();
    return 0;
}
0