#include using namespace std; using ll = long long; using ld = long double; using pll = array; using vl = vector; template using vec = vector; template using vv = vec>; template using vvv = vv>; template using minpq = priority_queue, greater>; #define all(a) (a).begin(),(a).end() #define rep(i, n) for (ll i = 0; i < (n); ++i) #define reps(i, l, r) for(ll i = (l); i < (r); ++i) #define rrep(i, l, r) for(ll i = (r)-1; i >= (l); --i) #define sz(x) (ll) (x).size() template bool chmax(T &a, const T& b) { return a < b ? a = b, true : false; } template bool chmin(T &a, const T& b) { return a > b ? a = b, true : false; } const ll mod = 998244353; // 1000000007; struct mint { ll x; mint(ll y = 0) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} mint &operator+=(const mint &p) { if ((x += p.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint &p) { x = (ll)(1ll * x * p.x % mod); return *this; } mint &operator/=(const mint &p) { *this *= p.inv(); return *this; } mint operator-() const { return mint(-x); } mint operator+(const mint &p) const { return mint(*this) += p; } mint operator-(const mint &p) const { return mint(*this) -= p; } mint operator*(const mint &p) const { return mint(*this) *= p; } mint operator/(const mint &p) const { return mint(*this) /= p; } bool operator==(const mint &p) const { return x == p.x; } bool operator!=(const mint &p) const { return x != p.x; } friend ostream &operator<<(ostream &os, const mint &p) { return os << p.x; } friend istream &operator>>(istream &is, mint &a) { ll t; is >> t; a = mint(t); return (is); } mint inv() const { return pow(mod - 2); } mint pow(ll n) const { mint ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } }; struct SCC { vv& g; vv dag, rg; vl cmp, ord; vec use; vv blng; SCC(vv& g) : g(g), use(sz(g), 0) { build(); } ll operator[](ll k) { return cmp[k]; } vl& belong(ll i) { return blng[i]; } void dfs(ll p) { if (use[p]) return; use[p] = 1; for (auto e : g[p]) dfs(e); ord.push_back(p); } void rdfs(ll p, ll cnt) { if (cmp[p] != -1) return; cmp[p] = cnt; for (auto e : rg[p]) rdfs(e, cnt); } void build() { rep(i, sz(g)) { dfs(i); } reverse(all(ord)); use.clear(), use.shrink_to_fit(); cmp.resize(sz(g), -1ll), rg.resize(sz(g)); rep(i, sz(g)) { for (auto e : g[i]) { rg[e].emplace_back(i); } } ll ptr = 0; for (ll i : ord) if (cmp[i] == -1) rdfs(i, ptr), ptr++; rg.clear(), rg.shrink_to_fit(); ord.clear(), ord.shrink_to_fit(); dag.resize(ptr), blng.resize(ptr); rep(i, sz(g)) { blng[cmp[i]].push_back(i); for (auto& to : g[i]) { ll x = cmp[i], y = cmp[to]; if (x == y) continue; dag[x].push_back(y); } } } }; void solve(){ ll N, M, K; cin >> N >> M >> K; vv G(N); vec E(M); rep(i, M){ ll u, v; cin >> u >> v; u--; v--; G[u].push_back(v); E[i] = {u, v}; } SCC scc(G); ll X = sz(scc.dag); vl a(X-1, 0); rep(i, M){ ll u = E[i][0], v = E[i][1]; if(abs(scc.cmp[u]-scc.cmp[v]) == 1){ a[min(scc.cmp[u], scc.cmp[v])]=1; } } if(a != vl(X-1, 1)){ cout << "No" << endl; return; } vl check(N, -1); vl bin(X, 0); rep(i, N){ if(check[i] == -1){ check[i] = 0; queue Q; Q.push(i); while(!Q.empty()){ ll p = Q.front(); Q.pop(); for(ll nx : G[p]){ if(scc.cmp[nx] != scc.cmp[p]) continue; if(check[nx] == -1){ check[nx] = 1 - check[p]; Q.push(p); } if(check[p] == check[nx]){ bin[scc.cmp[p]] = 1; } } } } } if(bin == vl(X, 1)){ cout << "Yes" << endl; } else cout << "No" << endl; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); int t = 1; // cin >> t; while(t--){ solve(); } }