結果
問題 | No.92 逃走経路 |
ユーザー |
![]() |
提出日時 | 2016-08-17 22:10:21 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 1,695 bytes |
コンパイル時間 | 1,946 ms |
コンパイル使用メモリ | 169,620 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-07 18:55:33 |
合計ジャッジ時間 | 2,602 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h>template<typename T> T in() { abort(); return T(); }template<> std::string in() { std::string str; std::cin >> str; return str; }template<> int in() { int x; scanf("%d", &x); return x; }template<typename T> void out(T x) { abort(); }template<> void out(const char* x) { printf("%s\n", x); }template<> void out(std::string x) { std::cout << x << std::endl; }template<> void out(int x) { printf("%d\n", x); }template<> void out(long x) { printf("%ld\n", x); }template<> void out(size_t x) { printf("%lu\n", x); }struct Edge {Edge() {}Edge(int from_, int to_, int cost_) : from(from_), to(to_), cost(cost_) {}int from;int to;int cost;};int n, m, k;Edge edge[1024];int d[1024];int main() {n = in<int>();m = in<int>();k = in<int>();for(int i = 0; i < m; ++i) {edge[i].from = in<int>();edge[i].to = in<int>();edge[i].cost = in<int>();}for(int i = 0; i < k; ++i) {d[i] = in<int>();}bool flags[2][1024];bool *xs = flags[0];bool *ys = flags[1];for(int i = 1; i <= n; ++i) {xs[i] = true;}for(int i = 0; i < k; ++i) {for(int j = 1; j <= n; ++j) ys[j] = false;for(int j = 0; j < m; ++j) {int from = edge[j].from;int to = edge[j].to;int cost = edge[j].cost;if( cost == d[i] ) {ys[to] = ys[to] or xs[from];ys[from] = ys[from] or xs[to];}}std::swap(xs, ys);}std::vector<int> res;for(int i = 1; i <= n; ++i) {if( xs[i] ) res.push_back(i);}out(res.size());printf("%d", res[0]);for(int i = 1; i < (int)res.size(); ++i) {printf(" %d", res[i]);}puts("");return 0;}