結果

問題 No.416 旅行会社
ユーザー tottoripapertottoripaper
提出日時 2016-10-01 22:33:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 205 ms / 4,000 ms
コード長 1,866 bytes
コンパイル時間 1,812 ms
コンパイル使用メモリ 153,456 KB
実行使用メモリ 14,620 KB
最終ジャッジ日時 2023-08-21 10:05:55
合計ジャッジ時間 4,724 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
11,440 KB
testcase_01 AC 3 ms
7,252 KB
testcase_02 AC 4 ms
7,256 KB
testcase_03 AC 4 ms
7,280 KB
testcase_04 AC 3 ms
7,204 KB
testcase_05 AC 3 ms
7,312 KB
testcase_06 AC 3 ms
7,256 KB
testcase_07 AC 4 ms
7,268 KB
testcase_08 AC 5 ms
7,268 KB
testcase_09 AC 12 ms
7,556 KB
testcase_10 AC 73 ms
11,380 KB
testcase_11 AC 74 ms
14,480 KB
testcase_12 AC 75 ms
14,508 KB
testcase_13 AC 66 ms
14,620 KB
testcase_14 AC 197 ms
13,172 KB
testcase_15 AC 204 ms
13,748 KB
testcase_16 AC 205 ms
14,336 KB
testcase_17 AC 198 ms
13,756 KB
testcase_18 AC 199 ms
13,540 KB
testcase_19 AC 131 ms
12,540 KB
testcase_20 AC 127 ms
12,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N, M, Q;
P bridge[200000];
bool broken[200000], used[200000];
int id[200000];
vector<int> graph[100000];
int res[100000];

void dfs(int u, int tag){
    used[u] = true;
    res[u] = tag;
    
    for(int v : graph[u]){
        if(!used[v]){
            dfs(v, tag);
        }
    }
}

int main(){
    //*
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    /*/
      /*/

    scanf("%d %d %d", &N, &M, &Q);

    for(int i=0;i<M;++i){
        scanf("%d %d", &fst(bridge[i]), &snd(bridge[i]));
        --fst(bridge[i]);
        --snd(bridge[i]);
    }

    sort(bridge, bridge+M);
    
    for(int i=0;i<Q;++i){
        P brokenBridge;
        scanf("%d %d", &fst(brokenBridge), &snd(brokenBridge));
        --fst(brokenBridge);
        --snd(brokenBridge);
        
        auto it = lower_bound(bridge, bridge+M, brokenBridge);
        if(it != bridge + M && *it == brokenBridge){
            broken[it-bridge] = true;
            id[i] = it - bridge;
        }
    }

    for(int i=0;i<M;++i){
        if(!broken[i]){
            graph[fst(bridge[i])].emplace_back(snd(bridge[i]));
            graph[snd(bridge[i])].emplace_back(fst(bridge[i]));
        }
    }

    dfs(0, -1);
    
    for(int i=Q-1;i>=0;--i){
        P b = bridge[id[i]];
        int u, v;
        tie(u, v) = b;

        graph[u].emplace_back(v);
        graph[v].emplace_back(u);
        
        if(used[u] && !used[v]){
            dfs(v, i+1);
        }else if(used[v] && !used[u]){
            dfs(u, i+1);
        }
    }

    for(int i=1;i<N;++i){
        printf("%d\n", res[i]);
    }
}
0