Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- vector<map<int, int>> g;
- vector<int> k_array;
- int ans = 0;
- void DFS(int &v, int i)
- {
- if (ans || i == (k_array.size())) return;
- bool found = false;
- for (auto v_i : g[v])
- {
- if (v_i.second == k_array[i])
- {
- v = v_i.first;
- DFS(v, i + 1);
- found = true;
- }
- if (ans) break;
- }
- if (!found)
- ans = 1;
- }
- int main()
- {
- int n, m;
- cin >> n >> m;
- g.resize(n);
- for (int i = 0; i < m; ++i)
- {
- int v1, v2, colour;
- cin >> v1 >> v2 >> colour;
- g[--v1].insert(make_pair(--v2, colour));
- g[v2].insert(make_pair(v1, colour));
- }
- int k;
- cin >> k;
- k_array.resize(k);
- for (int j = 0; j < k; ++j)
- {
- cin >> k_array[j];
- }
- int v = 0;
- DFS(v, 0);
- if (ans)
- cout << "INCORRECT";
- else
- cout << v + 1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement