{"problem":{"name":"Unique Path","description":{"content":"Snuke's mother gave Snuke an undirected graph consisting of $N$ vertices numbered $0$ to $N-1$ and $M$ edges. This graph was connected and contained no parallel edges or self-loops. One day, Snuke bro","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"agc038_d"},"statements":[{"statement_type":"Markdown","content":"Snuke's mother gave Snuke an undirected graph consisting of $N$ vertices numbered $0$ to $N-1$ and $M$ edges. This graph was connected and contained no parallel edges or self-loops.\nOne day, Snuke broke this graph. Fortunately, he remembered $Q$ clues about the graph. The $i$\\-th clue ($0 \\leq i \\leq Q-1$) is represented as integers $A_i,B_i,C_i$ and means the following:\n\n*   If $C_i=0$: there was exactly one simple path (a path that never visits the same vertex twice) from Vertex $A_i$ to $B_i$.\n*   If $C_i=1$: there were two or more simple paths from Vertex $A_i$ to $B_i$.\n\nSnuke is not sure if his memory is correct, and worried whether there is a graph that matches these $Q$ clues. Determine if there exists a graph that matches Snuke's memory.\n\n## Constraints\n\n*   $2 \\leq N \\leq 10^5$\n*   $N-1 \\leq M \\leq N \\times (N-1)/2$\n*   $1 \\leq Q \\leq 10^5$\n*   $0 \\leq A_i,B_i \\leq N-1$\n*   $A_i \\neq B_i$\n*   $0 \\leq C_i \\leq 1$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $M$ $Q$\n$A_0$ $B_0$ $C_0$\n$A_1$ $B_1$ $C_1$\n$\\vdots$\n$A_{Q-1}$ $B_{Q-1}$ $C_{Q-1}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"agc038_d","tags":[],"sample_group":[["5 5 3\n0 1 0\n1 2 1\n2 3 0","Yes\n\nFor example, consider a graph with edges $(0,1),(1,2),(1,4),(2,3),(2,4)$. This graph matches the clues."],["4 4 3\n0 1 0\n1 2 1\n2 3 0","No"],["10 9 9\n7 6 0\n4 5 1\n9 7 0\n2 9 0\n2 3 0\n4 1 0\n8 0 0\n9 1 0\n3 0 0","No"]],"created_at":"2026-03-03 11:01:14"}}