#include #include #include #include #include using namespace std; #pragma warning (disable: 4996) class UnionFind { public: vector par; void init(int sz) { par.resize(sz, -1); } int root(int pos) { if (par[pos] == -1) return pos; par[pos] = root(par[pos]); return par[pos]; } void unite(int u, int v) { u = root(u); v = root(v); if (u == v) return; par[u] = v; } bool same(int u, int v) { if (root(u) == root(v)) return true; return false; } }; int N, M, Q; int A[1 << 18], B[1 << 18]; int X[1 << 18], Y[1 << 18], Z[1 << 18]; int main() { // Step #1. Input scanf("%d%d", &N, &M); for (int i = 1; i <= M; i++) scanf("%d%d", &A[i], &B[i]); scanf("%d", &Q); for (int i = 1; i <= Q; i++) scanf("%d%d%d", &X[i], &Y[i], &Z[i]); // Step #2. Check assert(2 <= N && N <= 200000); assert(1 <= M && M <= 200000); assert(1 <= Q && Q <= 200000); map, int> Map; int cnt = 0; UnionFind UF; UF.init(N + 2); for (int i = 1; i <= M; i++) { assert(1 <= A[i] && A[i] < B[i] && B[i] <= N); assert(Map[make_pair(A[i], B[i])] != 1); Map[make_pair(A[i], B[i])] = 1; if (UF.same(A[i], B[i]) == false) { UF.unite(A[i], B[i]); cnt++; } } for (int i = 1; i <= Q; i++) { assert(1 <= X[i] && X[i] < Y[i] && Y[i] <= N); assert(1 <= Z[i] <= M); } assert(cnt == N - 1); cout << "Yay!" << endl; return 0; }