結果

問題 No.812 Change of Class
ユーザー veqcc
提出日時 2019-04-12 21:58:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,738 bytes
コンパイル時間 1,178 ms
コンパイル使用メモリ 112,720 KB
実行使用メモリ 10,816 KB
最終ジャッジ日時 2024-06-12 07:14:29
合計ジャッジ時間 13,682 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
typedef pair <int, int> P;

vector <int> edges[100005];

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        edges[p].push_back(q);
        edges[q].push_back(p);
    }

    int Q;
    cin >> Q;

    for (int x = 0; x < Q; x++) {
        int a;
        cin >> a;
        a--;

        priority_queue <P, vector<P>, greater<P>> q;
        q.push(P(0, a));

        vector <bool> visited(n, false);
        visited[a] = true;

        vector <int> cost(n, 1e9);
        cost[a] = 0;

        int ans_count = 0;
        int ans_depth = 0;

        while (q.size()) {
            P cur = q.top();
            q.pop();

            int now = cur.second;
            int c = cur.first;

            if (cost[now] < c) continue;

            for (int node : edges[now]) {
                if (!visited[node]) ans_count++;
                visited[node] = true;

                if (cost[node] > c + 1) {
                    cost[node] = c + 1;
                    ans_depth = c + 1;
                    q.push(P(c+1, node));
                }
            }
        }

        if (ans_depth == 1) {
            ans_depth = 0;
        } else {
            ans_depth = ans_depth % 2 == 0 ? ans_depth / 2 : ans_depth / 2 + 1;
        }

        cout << ans_count << " " << ans_depth << "\n";
    }

    return 0;
}
0