結果

問題 No.92 逃走経路
ユーザー cormorancormoran
提出日時 2016-06-21 17:29:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 1,916 bytes
コンパイル時間 830 ms
コンパイル使用メモリ 94,592 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-19 23:39:40
合計ジャッジ時間 1,715 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,948 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 15 ms
6,940 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 7 ms
6,940 KB
testcase_10 AC 26 ms
6,944 KB
testcase_11 AC 24 ms
6,940 KB
testcase_12 AC 29 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 8 ms
6,944 KB
testcase_15 AC 11 ms
6,940 KB
testcase_16 AC 8 ms
6,940 KB
testcase_17 AC 9 ms
6,944 KB
testcase_18 AC 6 ms
6,944 KB
testcase_19 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<tuple>
#include<numeric>
using namespace std;

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl
// vector
template<class T> ostream& operator << (ostream &os , const vector<T> &v) {
    for(const T &t : v) os << "\t" << t; return os << endl;
}
template<class T> istream& operator >> (istream &is , vector<T> &v) {
    for(T &a : v) is >> a; return is;
}
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) {
    return os << "<" << v.first << " " << v.second << ">";
}



bool solve() {
    int N, M, K; cin >> N >> M >> K;
    vector<vector<pii>> E(N);
    map<int, vector<int>> mp;
    rep(i, M) {
        int a, b, c; cin >> a >> b >> c;
        --a; --b;
        E[a].push_back(make_pair(b, c));
        E[b].push_back(make_pair(a, c));
        mp[c].push_back(a);
        mp[c].push_back(b);
    }
    vector<int> D(K); cin >> D;
    set<int> ans[2];
    int cnt = 0;
    ans[cnt].insert(all(mp[D[0]]));

    repeat(i, 1, K) {
        ans[cnt^1].clear();
        for(int now : ans[cnt]) {
            for(pii nxt : E[now]) {
                if(nxt.second == D[i]) ans[cnt^1].insert(nxt.first);
            }
        }
        cnt ^= 1;
    }

    
    cout << ans[cnt].size() << endl;
    for(auto a = ans[cnt].begin(); a != ans[cnt].end(); a++) {
        if(a != ans[cnt].begin()) cout << " ";
        cout << *a + 1;
    }
    cout << endl;
    
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}
0