#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } void solve() { int n, m, k; cin >> n >> m >> k; vector> g(n); atcoder::scc_graph sc(n); rep(i, 0, m) { int u, v; cin >> u >> v; u--, v--; g[u].push_back(v); sc.add_edge(u, v); } auto vv = sc.scc(); m = vv.size(); vector id(n, -1); vector> sub(n); { vector nx(m, -1); int t = 0; for (auto v : vv) { for (int x : v) id[x] = t; t++; } if (id[0] != 0) { cout << "No\n"; return; } rep(i, 0, n) { for (int j : g[i]) { if (id[i] == id[j]) { sub[i].push_back(j); continue; } if (nx[id[i]] == -1) nx[id[i]] = id[j]; else if (nx[id[i]] != id[j]) { cout << "No\n"; return; } } } } int b = 0; vector col(n, -1); rep(i, 0, m) { if (vv[i].size() == 1) { if (b) { b = 0; continue; } else { cout << "No\n"; return; } } auto dfs = [&](auto self, int nw) -> bool { for (int nx : sub[nw]) { if (col[nx] != -1) { if (col[nx] == col[nw]) return 1; } else { col[nx] = col[nw] ^ 1; if (self(self, nx)) return 1; } } return 0; }; col[vv[i][0]] = 0; if (!dfs(dfs, vv[i][0])) { cout << "No\n"; return; } b = 1; } cout << "Yes\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int t = 1; // cin >> t; while (t--) solve(); }