結果

問題 No.416 旅行会社
ユーザー h_nosonh_noson
提出日時 2016-09-16 01:16:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,748 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 92,352 KB
実行使用メモリ 812,988 KB
最終ジャッジ日時 2024-04-28 13:58:46
合計ジャッジ時間 6,942 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
46,284 KB
testcase_01 AC 10 ms
28,224 KB
testcase_02 AC 10 ms
28,228 KB
testcase_03 AC 10 ms
28,356 KB
testcase_04 AC 10 ms
28,356 KB
testcase_05 AC 10 ms
28,228 KB
testcase_06 AC 10 ms
27,096 KB
testcase_07 AC 11 ms
27,224 KB
testcase_08 AC 14 ms
29,000 KB
testcase_09 AC 28 ms
31,428 KB
testcase_10 AC 107 ms
46,276 KB
testcase_11 AC 135 ms
51,140 KB
testcase_12 AC 141 ms
53,560 KB
testcase_13 MLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
set<int> group[200000];

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

void unite(int x, int y, int event) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (x == 0) {
        par[y] = x;
        for (auto z: group[y]) ans[z] = event;
        group[x].insert(group[y].begin(),group[y].end());
    }
    else {
        if (y == 0) for (auto z: group[x]) ans[z] = event;
        par[x] = y;
        group[y].insert(group[x].begin(),group[x].end());
    }
}

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]);
    }

    // init
    REP (i,n) {
        par[i] = i;
        group[i].insert(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