/* -*- coding: utf-8 -*- * * 92.cc: No.92 逃走経路 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100; const int MAX_M = 1000; const int MAX_K = 1000; /* typedef */ typedef pair pii; typedef vector vpii; typedef set si; /* global variables */ int n, m, k; int as[MAX_M], bs[MAX_M], cs[MAX_M], ds[MAX_K]; vpii nbrs[MAX_N]; si ps[2]; /* subroutines */ /* main */ int main() { cin >> n >> m >> k; for (int i = 0; i < m; i++) { cin >> as[i] >> bs[i] >> cs[i]; as[i]--, bs[i]--; nbrs[as[i]].push_back(pii(bs[i], cs[i])); nbrs[bs[i]].push_back(pii(as[i], cs[i])); } for (int i = 0; i < k; i++) cin >> ds[i]; for (int i = 0; i < m; i++) if (cs[i] == ds[0]) { ps[0].insert(as[i]); ps[0].insert(bs[i]); } int cur = 0, nxt = 1; for (int i = 1; i < k; i++) { si &p0 = ps[cur], &p1 = ps[nxt]; p1.clear(); for (si::iterator sit = p0.begin(); sit != p0.end(); sit++) { vpii& nbru = nbrs[*sit]; for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) { int &v = vit->first, &c = vit->second; if (c == ds[i]) p1.insert(v); } } cur ^= 1, nxt ^= 1; } si &pc = ps[cur]; printf("%lu\n", pc.size()); bool first = true; for (si::iterator sit = pc.begin(); sit != pc.end(); sit++) { if (! first) putchar(' '); printf("%d", *sit + 1); first = false; } putchar('\n'); return 0; }