結果

問題 No.92 逃走経路
ユーザー なおなお
提出日時 2014-12-07 19:55:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 94 ms / 5,000 ms
コード長 1,000 bytes
コンパイル時間 1,448 ms
コンパイル使用メモリ 162,200 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 09:32:11
合計ジャッジ時間 2,754 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 22 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 94 ms
4,380 KB
testcase_11 AC 84 ms
4,380 KB
testcase_12 AC 63 ms
4,380 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 19 ms
4,376 KB
testcase_16 AC 15 ms
4,376 KB
testcase_17 AC 16 ms
4,380 KB
testcase_18 AC 9 ms
4,380 KB
testcase_19 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))

int N,M,K;
map<int,vector<pair<int,int> >> m;

int main(){
    cin >>N>>M>>K;

    REP(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        m[c].push_back(make_pair(a,b));
    }
    int d;
    set<int> s;
    cin >> d;
    for(auto it = m[d].begin(); it != m[d].end(); ++it){
        s.insert(it->first);
        s.insert(it->second);
    }
    REP(i,K-1){
        cin >> d;
        set<int> s2;
        for(auto it = m[d].begin(); it != m[d].end(); ++it){
            if(s.count(it->first)) s2.insert(it->second);
            if(s.count(it->second)) s2.insert(it->first);
        }
        s = move(s2);
    }
    vector<int> v;
    for(auto it = s.begin(); it != s.end(); ++it){
        v.push_back(*it);
    }
    cout << v.size() << endl;
    REP(i,v.size()-1){
        cout << v[i] << " ";
    }
    cout << v.back() << endl;
    return 0;
}
0