1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
| #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
struct edge {
int from,to;
int cost;
edge(int t,int c) : to(t),cost(c) {}
edge(int f,int t,int c) : from(f),to(t),cost(c) {}
bool operator<(const edge &e) const {
return cost < e.cost;
}
};
vector<int> v;
int n,m,k;
int main() {
cin >> n >> m >> k;
map<int,vector<edge> > edges;
rep(i,m) {
int a,b,c;
cin >> a >> b >> c;
a--;
b--;
edges[c].push_back(edge(a,b,c));
edges[c].push_back(edge(b,a,c));
}
v.resize(k);
rep(i,k) cin >> v[i];
vector<int> ans(n);
rep(i,n) ans[i] = i;
rep(i,k) {
bool used[105];
memset(used,0,sizeof(used));
rep(j,ans.size()) {
used[ans[j]] = true;
}
vector<edge> es = edges[v[i]];
vector<int> temp;
rep(j,es.size()) {
int f = es[j].from;
int t = es[j].to;
if(used[f]) {
temp.push_back(t);
}
}
sort(temp.begin(),temp.end());
temp.erase(unique(temp.begin(),temp.end()),temp.end());
ans.resize(temp.size());
rep(j,temp.size()) ans[j] = temp[j];
}
sort(ans.begin(),ans.end());
cout << ans.size() << endl;
rep(i,ans.size()) {
cout << ans[i] + 1;
if(i == ans.size()-1) cout << endl;
else cout << " ";
}
return 0;
}
|