Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- signed main() {
- int n, m;
- cin >> n >> m;
- int k;
- cin >> k;
- int a[k], b[k], c[k];
- for (int i = 0; i < k; i++) {
- cin >> a[i] >> b[i] >> c[i];
- }
- bool used[n + 1];
- memset(used, false, sizeof(used));
- int x;
- for (int i = 0; i < m; i++) {
- cin >> x;
- used[x] = true;
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < k; j++) {
- if (used[a[j]] && used[b[j]]) {
- used[c[j]] = true;
- }
- }
- }
- int ans = 0;
- for (int i = 1; i <= n; i++) {
- if (used[i])
- ans++;
- }
- cout << ans << '\n';
- for (int i = 1; i <= n; i++) {
- if (used[i])
- cout << i << ' ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement