結果

問題 No.92 逃走経路
ユーザー face4face4
提出日時 2018-05-20 16:27:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 5,000 ms
コード長 1,058 bytes
コンパイル時間 890 ms
コンパイル使用メモリ 89,328 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 00:04:29
合計ジャッジ時間 2,706 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 25 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 115 ms
4,380 KB
testcase_11 AC 103 ms
4,380 KB
testcase_12 AC 72 ms
4,380 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 15 ms
4,380 KB
testcase_15 AC 21 ms
4,380 KB
testcase_16 AC 17 ms
4,384 KB
testcase_17 AC 17 ms
4,380 KB
testcase_18 AC 10 ms
4,384 KB
testcase_19 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<map>
#include<vector>
#include<set>

using namespace std;

int main(){
    int n, m, k, a, b, c;
    cin >> n >> m >> k;
    map<int, vector<pair<int,int>>> pay;

    for(int i = 0; i < m; i++){
        cin >> a >> b >> c;
        pay[c].push_back(make_pair(a,b));
        pay[c].push_back(make_pair(b,a));
    }

    set<int> pos;
    cin >> a;
    for(pair<int,int> p : pay[a]){
        pos.insert(p.second);
    }

    for(int i = 1; i < k; i++){
        cin >> a;
        set<int> after;
        for(int j = 0; j < pay[a].size(); j++){
            pair<int,int> p = pay[a][j];
            if(pos.find(p.first)!=pos.end())    after.insert(p.second);
        }

        pos = after;

        // cout << "after " << a << endl;
        // for(auto p : pos){
        //     cout << p << endl;
        // }
    }

    set<int>::iterator it = pos.begin();
    cout << pos.size() << endl;
    for(int i = 0; i < pos.size(); i++){
        if(i)   cout << " ";
        cout << *it;
        it++;
    }
    cout << endl;

    return 0;
}
0