結果

問題 No.416 旅行会社
ユーザー konsin_tokagekonsin_tokage
提出日時 2018-06-05 14:36:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,064 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 77,272 KB
実行使用メモリ 14,816 KB
最終ジャッジ日時 2023-09-12 22:25:06
合計ジャッジ時間 8,247 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
using namespace std;
vector<vector<int>> g;
vector<int> r, s;
void dfs(int i, int x){
    s.push_back(i);
    while(!s.empty()){
        int j = s.back();
        s.pop_back();
        if(r[j]) continue;
        r[j] = x;
        for(int k: g[j]) s.push_back(k);
    }
}
int main(){
    int n, m, q, a, b;
    cin >> n >> m >> q;
    set<pair<int,int>> u;
    for(int i=0; i<m; ++i){
        cin >> a >> b;
        u.emplace(a-1, b-1);
    }
    vector<pair<int,int>> e;
    for(int i=0; i<q; ++i){
        cin >> a >> b;
        u.erase({a-1,b-1});
        e.emplace_back(a-1, b-1);
    }
    g.resize(n);
    for(auto p: u){
        int i = p.first, j = p.second;
        g[i].push_back(j);
        g[j].push_back(i);
    }
    r.resize(n);
    dfs(0, -1);
    while(q--){
        int i = e[q].first, j = e[q].second;
        g[i].push_back(j);
        g[j].push_back(i);
        if(!(r[i]==0&&r[j]==0)){
            dfs(i, q+1);
            dfs(j, q+1);
        }
    }
    for(int i: r) cout << i << endl;
}
0