#include "testlib.h"
#include <bits/stdc++.h>

#define ll long long
using namespace std;

vector<vector<int>> g;
vector<char> used;


bool dfs(int v, int par = -1) {
    used[v] = 1;
    for (int to : g[v]) {
        if (to == par || used[to] == 2) continue;
        if (used[to] == 1)
            return true;
        bool r = dfs(to, v);
        if (r)
            return true;
    }
    used[v] = 2;
    return false;
}

 
int main(int argc, char* argv[]) {
    registerTestlibCmd(argc, argv);

    int n = inf.readInt();
    int m = inf.readInt();
    g.resize(n);
    used.resize(n);
    multiset<pair<int, int>> need;
    for (int i = 0; i < m; ++i) {
        int a = inf.readInt();
        int b = inf.readInt();
        int c = inf.readInt();
        --a; --b;
        if (c == 1) {
            g[a].push_back(b);
        } else {
            need.emplace(min(a, b), max(a, b));
        }
    }
    int k = need.size();
    for (int i = 0; i < k; ++i) {
        int a = ouf.readInt(1, n);
        int b = ouf.readInt(1, n);
        --a; --b;
        pair<int, int> cur(min(a, b), max(a, b));
        if (!need.count(cur))
            quitf(_wa, "edge is not from original graph");
        need.erase(need.find(cur));
        g[a].push_back(b);
    }
    if (!need.empty())
        quitf(_wa, "some edges not found");

    bool ok = true;
    for (int i = 0; i < n; ++i) {
        if (!used[i])
            if (dfs(i))
                ok = false;
    }
    if (ok)
        quitf(_ok, "no cycles");
    else
        quitf(_wa, "found cycle");

    return 0;
}
