結果

問題 No.416 旅行会社
ユーザー Tatsuno
提出日時 2016-08-26 23:45:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 663 ms / 4,000 ms
コード長 1,984 bytes
コンパイル時間 1,892 ms
コンパイル使用メモリ 179,828 KB
実行使用メモリ 20,864 KB
最終ジャッジ日時 2024-12-14 19:56:06
合計ジャッジ時間 9,017 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int32_t; using i64 = int64_t; using f64 = double_t; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i64 i = 0; i < (n); ++i)
#define range(n, m, i) for (i64 i = (n); i < (m); ++i)
#define upto(n, m, i) for (i64 i = (n); i <= (m); ++i)
#define downto(n, m, i) for (i64 i = (n); i >= (m); --i)
#define foreach(xs, x) for (auto &x : (xs))
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define maximum(xs) (*max_element(all(xs)))
#define minimum(xs) (*min_element(all(xs)))
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
const i64 MOD = 1000000007;

i32 n, m, q;
i32 d[200001];

set<pair<i32, i32>> ab;
vec<i32> g[200001];

void scan(i32 c, i32 v) {
    if (d[c] == 0) {
        d[c] = v;
    }
    else {
        return;
    }
    times(g[c].size(), i) {
        scan(g[c][i], v);
    }
}

i32 main()
{
    cin >> n >> m >> q;
    vec<pair<i32, i32>> cd(q);

    times(m, i) {
        i32 a, b; cin >> a >> b;
        ab.insert(make_pair(a, b));
    }
    times(q, i) {
        cin >> cd[i].first >> cd[i].second;
        ab.erase(cd[i]);
    }

    reverseall(cd);
    for (auto it = ab.begin(); it != ab.end(); it++) {
        g[it->first].append(it->second);
        g[it->second].append(it->first);
    }

    scan(1, -1);

    downto(q, 1, j) {
        i32 i = q-j;
        g[cd[i].first].append(cd[i].second);
        g[cd[i].second].append(cd[i].first);
        if (d[cd[i].first] != 0 || d[cd[i].second] != 0) {
            scan(cd[i].first, j);
            scan(cd[i].second, j);
        }
    }

    upto(2, n, i) {
        cout << d[i] << endl;
    }
    return 0;
}
0