結果

問題 No.92 逃走経路
ユーザー noriocnorioc
提出日時 2014-12-07 20:07:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 1,550 bytes
コンパイル時間 627 ms
コンパイル使用メモリ 69,596 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-02 09:35:14
合計ジャッジ時間 1,908 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 34 ms
4,384 KB
testcase_10 AC 32 ms
4,384 KB
testcase_11 AC 35 ms
4,388 KB
testcase_12 AC 35 ms
4,380 KB
testcase_13 AC 16 ms
4,376 KB
testcase_14 AC 23 ms
4,376 KB
testcase_15 AC 36 ms
4,376 KB
testcase_16 AC 29 ms
4,380 KB
testcase_17 AC 38 ms
4,384 KB
testcase_18 AC 23 ms
4,380 KB
testcase_19 AC 11 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define For(i,x) for (int i=0; i<(int)(x); i++)

typedef vector<int> vi;

const int N = 110;

void calc(int n, const vi& ks, const set<int> adj[][N]) {
    
    set<int> nodes;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) continue;

            
            if (adj[i][j].find(ks[0]) != adj[i][j].end()) {
                nodes.insert(j);
            }
        }
    }
    
    for (int i = 1; i < ks.size(); i++) {
        int cost = ks[i];
        set<int> nexts;

        for (std::set<int>::iterator p = nodes.begin(); p != nodes.end(); ++p) {
            int node = *p;
            for (int j = 1; j <= n; j++) {
                if (node == j) continue;

                if (adj[node][j].find(cost) != adj[node][j].end()) {
                    nexts.insert(j);
                }
            }
        }
        nexts.swap(nodes);
    }

    vi v(nodes.begin(), nodes.end());
    printf("%d\n", (int)v.size());
    For(i, v.size()) {
        if (i > 0) printf(" ");
        printf("%d", v[i]);
    }
    printf("\n");
}

int main() {
    int n, m, k;
    scanf("%d %d %d", &n, &m, &k);

    std::set<int> adj[N][N];
    For(i, m) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);

        adj[a][b].insert(c);
        adj[b][a].insert(c);
    }

    vi ks(k);
    For(i, k) scanf("%d", &ks[i]);

    calc(n, ks, adj);
}
0