結果

問題 No.416 旅行会社
ユーザー h_nosonh_noson
提出日時 2016-09-16 01:31:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 207 ms / 4,000 ms
コード長 1,682 bytes
コンパイル時間 1,033 ms
コンパイル使用メモリ 91,248 KB
実行使用メモリ 38,476 KB
最終ジャッジ日時 2023-08-21 10:06:20
合計ジャッジ時間 4,498 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
31,808 KB
testcase_01 AC 8 ms
22,468 KB
testcase_02 AC 8 ms
22,464 KB
testcase_03 AC 8 ms
22,452 KB
testcase_04 AC 8 ms
22,464 KB
testcase_05 AC 8 ms
22,724 KB
testcase_06 AC 8 ms
22,468 KB
testcase_07 AC 9 ms
22,504 KB
testcase_08 AC 10 ms
22,644 KB
testcase_09 AC 17 ms
23,296 KB
testcase_10 AC 79 ms
31,680 KB
testcase_11 AC 77 ms
32,052 KB
testcase_12 AC 81 ms
33,300 KB
testcase_13 AC 80 ms
36,712 KB
testcase_14 AC 202 ms
38,088 KB
testcase_15 AC 204 ms
38,324 KB
testcase_16 AC 207 ms
38,476 KB
testcase_17 AC 204 ms
38,300 KB
testcase_18 AC 203 ms
38,176 KB
testcase_19 AC 127 ms
31,988 KB
testcase_20 AC 126 ms
31,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int par[200000], ans[200000];
vector<int> child[200000];

int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}

void dfs(int x, int event) {
    ans[x] = event;
    for (auto y: child[x]) dfs(y,event);
}

void unite(int x, int y, int event) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (x == 0) {
        dfs(y,event);
        par[y] = x;
    }
    else if (y == 0) {
        dfs(x,event);
        par[x] = y;
    }
    else {
        par[x] = y;
        child[y].push_back(x);
    }
}

vector<int> e[200000];
set<int> del[200000];
int C[200000], D[200000];

int main(void) {
    int i, n, m, q;
    scanf("%d%d%d",&n,&m,&q);
    REP (i,m) {
        int a, b;
        scanf("%d%d",&a,&b);
        a--; b--;
        e[a].push_back(b);
    }
    REP (i,q) {
        scanf("%d%d",&C[i],&D[i]);
        C[i]--; D[i]--;
        del[C[i]].insert(D[i]);
    }

    REP (i,n) par[i] = i;

    REP (i,n) for (auto x: e[i]) if (!del[i].count(x)) {
        unite(i,x,-1);
    }
    RREP (i,q) {
        unite(C[i],D[i],i+1);
    }
    REP (i,1,n-1) printf("%d\n",ans[i]);
    return 0;
}
0