intread() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar(); return x * f; }
structDsu { int fa[N], d[N]; structTmp { int x, y, add; }; stack<Tmp> s; intfind(int x) { while (x != fa[x]) x = fa[x]; return x; } voidinit(int n) { while (!s.empty()) s.pop(); for (int i = 1; i <= n; i++) fa[i] = i, d[i] = 0; } voidmerge(int x, int y) { int xx = find(x); int yy = find(y); if (d[xx] > d[yy]) swap(xx, yy); s.push((Tmp){xx, yy, d[xx] == d[yy]}); fa[xx] = yy; d[yy] += (d[xx] == d[yy]); } voidret(int o) { while (s.size() > o) { Tmp x = s.top(); fa[x.x] = x.x; d[x.y] -= x.add; s.pop(); } } } d; vector<pii> e[N << 2]; int n, m, k; int ans[N]; voidinsert(int pos, int ql, int qr, int l, int r, pii o) { if (ql <= l && r <= qr) { e[pos].push_back(o); return; } int mid = (l + r) >> 1; if (ql <= mid) insert(pos << 1, ql, qr, l, mid, o); if (qr > mid) insert(pos << 1 | 1, ql, qr, mid + 1, r, o); }
voidsolve(int pos, int l, int r) { int o = d.s.size(); bool flag = 1;
for (pii i : e[pos]) { int x = d.find(i.first); int y = d.find(i.second); if (x == y) { for (int i = l; i <= r; i++) ans[i] = 0; flag = 0; break; } d.merge(i.first, i.second + n); d.merge(i.first + n, i.second); } int mid = (l + r) >> 1; if (flag) { if (l == r) return; solve(pos << 1, l, mid), solve(pos << 1 | 1, mid + 1, r); }
d.ret(o); }
intmain() { n = read(), m = read(), k = read(); d.init(2 * n); for (int i = 1; i <= k; i++) ans[i] = 1; for (int i = 1; i <= m; i++) { int u = read(), v = read(), l = read(), r = read(); insert(1, l + 1, r, 1, k, mk(u, v)); }
solve(1, 1, k); for (int i = 1; i <= k; i++) { puts(ans[i] ? "Yes" : "No"); } }