結果
| 問題 |
No.92 逃走経路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-12-07 19:55:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 89 ms / 5,000 ms |
| コード長 | 1,000 bytes |
| コンパイル時間 | 1,638 ms |
| コンパイル使用メモリ | 176,748 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-11 16:18:53 |
| 合計ジャッジ時間 | 2,779 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#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;
}