using AtCoder;
using AtCoder.Internal;
using Kzrnm.Competitive;
using Kzrnm.Competitive.IO;
using System;
using System.Buffers;
using System.Buffers.Text;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using static Kzrnm.Competitive.Global;
using 凾 = System.Runtime.CompilerServices.MethodImplAttribute;
partial class Program
{
const bool __ManyTestCases = false;
#if !LOCAL_RUNNING
static void Main()=>new Program(new PropertyConsoleReader(),new Utf8ConsoleWriter()).Run();
[凾(256)]
#endif
private ConsoleOutput? Calc()
{
int N = cr;
int M = cr;
int Q = cr;
var g = GraphBuilder.Create(N, cr, M, false).ToGraph();
var es = g.RemoveCycle();
var uf = new DSU(N);
foreach (var (u, v) in es)
uf.Merge(u, v);
while (--Q >= 0)
{
cw.WriteLine(YesNo(uf.Same(cr.Int0, cr.Int0)));
}
return null;
}
}
public static class 閉路削除DFS
{
enum Status { None, Active, Done }
///
/// 閉路があれば返す。なければ(-1, null)
///
[凾(256)]
public static (int u, int v)[] RemoveCycle(this IGraph graph)
where TNode : IGraphNode
where TEdge : IGraphEdge
{
List<(int u, int v)> es = new List<(int u, int v)>();
var g = graph.AsArray();
var statuses = new Status[g.Length];
var depths = new int[g.Length];
int DFS(int v, int prev, int depth)
{
int res = -1;
statuses[v] = Status.Active;
depths[v] = depth;
foreach (var e in g[v].Children)
{
var child = e.To;
switch (statuses[child])
{
case Status.None:
var nr = DFS(child, v, depth + 1);
if (res < 0 || nr >= 0 && depths[res] > depths[nr])
res = nr;
if (nr < 0)
es.Add((v, child));
break;
case Status.Active:
if (!g[v].IsDirected && child == prev)
break;
if (depths[v] < depths[child])
break;
if (res < 0 || depths[res] > depths[child])
res = child;
break;
default:
if (res < 0) es.Add((v, child));
break;
}
}
if (res == v) res = -1;
statuses[v] = Status.Done;
return res;
}
for (var i = 0; i < g.Length; i++)
{
if (statuses[i] == Status.None)
DFS(i, -1, 0);
}
return es.ToArray();
}
}
#region Expanded by https://github.com/kzrnm/SourceExpander
//LICENSE:
//https://github.com/kzrnm/Kzrnm.Competitive/blob/master/LICENSE
//https://github.com/kzrnm/Kzrnm.Competitive/blob/master/3rd-party%20Licenses.txt
#pragma warning disable
namespace AtCoder{public class DSU{internal readonly int _n;public readonly int[]_parentOrSize;public DSU(int n){_n=n;_parentOrSize=new int[n];_parentOrSize.AsSpan().Fill(-1);}[凾(256)]public int Merge(int a,int b){int x=Leader(a),y=Leader(b);if(x==y)return x;if(-_parentOrSize[x]<-_parentOrSize[y])(x,y)=(y,x);_parentOrSize[x]+=_parentOrSize[y];_parentOrSize[y]=x;return x;}[凾(256)]public bool Same(int a,int b){return Leader(a)==Leader(b);}[凾(256)]public int Leader(int a){if(_parentOrSize[a]<0)return a;while(0<=_parentOrSize[_parentOrSize[a]]){(a,_parentOrSize[a])=(_parentOrSize[a],_parentOrSize[_parentOrSize[a]]);}return _parentOrSize[a];}[凾(256)]public int Size(int a){return-_parentOrSize[Leader(a)];}[凾(256)]public int[][]Groups(){int[]leaderBuf=new int[_n];int[]id=new int[_n];var resultList=new SimpleList(_n);for(int i=0;i:IEnumerable<(int from,TEdge edge)>{public readonly int[]Start;public readonly TEdge[]EList;public CSR(int n,ICollection<(int from,TEdge e)>edges){Start=new int[n+1];EList=new TEdge[edges.Count];foreach(var(from,_)in edges){Start[from+1]++;}for(int i=1;i<=n;i++){Start[i]+=Start[i-1];}var counter=(int[])Start.Clone();foreach(var(from,e)in edges){EList[counter[from]++]=e;}}public Enumerator GetEnumerator()=>new Enumerator(this);IEnumerator<(int from,TEdge edge)>IEnumerable<(int from,TEdge edge)>.GetEnumerator()=>GetEnumerator();IEnumerator IEnumerable.GetEnumerator()=>GetEnumerator();public struct Enumerator:IEnumerator<(int from,TEdge edge)>{public Enumerator(CSRg){_g=g;index=-1;start=0;}private readonly CSR_g;private int index;private int start;public(int from,TEdge edge)Current=>(start,_g.EList[index]);object IEnumerator.Current=>Current;[凾(256)]public bool MoveNext(){if( ++index<_g.Start[start+1])return true;return MoveNextStart();}private bool MoveNextStart(){for( ++start;start+1<_g.Start.Length;++start)if(index<_g.Start[start+1])return true;return false;}public void Reset(){index=-1;start=0;}void IDisposable.Dispose(){}}}}
namespace AtCoder.Internal{public class SimpleList:IList,IReadOnlyList{private T[]data;private const int DefaultCapacity=2;public SimpleList(){data=new T[DefaultCapacity];}public SimpleList(int capacity){data=new T[Math.Max(capacity,DefaultCapacity)];}public SimpleList(IEnumerablecollection){if(collection is ICollectioncol){data=new T[col.Count];col.CopyTo(data,0);Count=col.Count;}else{data=new T[DefaultCapacity];foreach(var item in collection)Add(item);}}[凾(256)]public MemoryAsMemory()=>new Memory(data,0,Count);[凾(256)]public SpanAsSpan()=>new Span(data,0,Count);public ref T this[int index]{[凾(256)]get{if((uint)index>=(uint)Count)ThrowIndexOutOfRangeException();return ref data[index];}}public int Count{get;private set;}[凾(256)]public void Add(T item){if((uint)Count>=(uint)data.Length)Array.Resize(ref data,data.Length<<1);data[Count++]=item;}[凾(256)]public void RemoveLast(){if( --Count<0)ThrowIndexOutOfRangeException();}[凾(256)]public SimpleListReverse(){Array.Reverse(data,0,Count);return this;}[凾(256)]public SimpleListReverse(int index,int count){Array.Reverse(data,index,count);return this;}[凾(256)]public SimpleListSort(){Array.Sort(data,0,Count);return this;}[凾(256)]public SimpleListSort(IComparercomparer){Array.Sort(data,0,Count,comparer);return this;}[凾(256)]public SimpleListSort(int index,int count,IComparercomparer){Array.Sort(data,index,count,comparer);return this;}[凾(256)]public void Clear()=>Count=0;[凾(256)]public bool Contains(T item)=>IndexOf(item)>=0;[凾(256)]public int IndexOf(T item)=>Array.IndexOf(data,item,0,Count);[凾(256)]public void CopyTo(T[]array,int arrayIndex)=>Array.Copy(data,0,array,arrayIndex,Count);[凾(256)]public T[]ToArray()=>AsSpan().ToArray();bool ICollection.IsReadOnly=>false;T IList.this[int index]{get=>data[index];set=>data[index]=value;}T IReadOnlyList.this[int index]{get=>data[index];}void IList.Insert(int index,T item)=>throw new NotSupportedException();bool ICollection.Remove(T item)=>throw new NotSupportedException();void IList.RemoveAt(int index)=>throw new NotSupportedException();IEnumerator IEnumerable.GetEnumerator()=>((IEnumerable)this).GetEnumerator();IEnumeratorIEnumerable.GetEnumerator(){for(int i=0;i.Enumerator GetEnumerator()=>AsSpan().GetEnumerator();private static void ThrowIndexOutOfRangeException()=>throw new IndexOutOfRangeException();}}
namespace Kzrnm.Competitive.IO{using static Utf8Parser;using _R=ConsoleReader;public class ConsoleReader{internal const int BufSize=1<<12;internal readonly Stream input;internal readonly Encoding encoding;internal readonly byte[]buf;internal int pos;internal int len;[凾(256)]public ConsoleReader():this(Console.OpenStandardInput(),Console.InputEncoding,BufSize){}[凾(256)]public ConsoleReader(Stream input,Encoding encoding):this(input,encoding,BufSize){}[凾(256)]public ConsoleReader(Stream input,Encoding encoding,int bufferSize){this.input=input;this.encoding=encoding;buf=new byte[bufferSize];}[凾(256)]private void FillEntireNumber(){if((uint)pos>=(uint)buf.Length)FillNextBuffer();while(buf[pos]<=' ')if( ++pos>=len)FillNextBuffer();if(pos+21>=buf.Length&&buf[buf.Length-1]>' ')FillEntireNumberImpl();}private void FillEntireNumberImpl(){buf.AsSpan(pos,len-pos).CopyTo(buf);len-=pos;pos=0;var numberOfBytes=input.Read(buf,len,buf.Length-len);if(numberOfBytes==0)buf[len++]=10;else if(numberOfBytes+len=len)FillNextBuffer();return buf[pos++];}[凾(256)]public T Read(){if(typeof(T)==typeof(int))return(T)(object)Int();if(typeof(T)==typeof(uint))return(T)(object)UInt();if(typeof(T)==typeof(long))return(T)(object)Long();if(typeof(T)==typeof(ulong))return(T)(object)ULong();if(typeof(T)==typeof(double))return(T)(object)Double();if(typeof(T)==typeof(decimal))return(T)(object)Decimal();if(typeof(T)==typeof(char))return(T)(object)Char();if(typeof(T)==typeof(string))return(T)(object)Ascii();return Throw();}static T Throw()=>throw new NotSupportedException(typeof(T).Name);[凾(256)]public int Int(){FillEntireNumber();TryParse(buf.AsSpan(pos),out int v,out int bc);pos+=bc;return v;}[凾(256)]public uint UInt(){FillEntireNumber();TryParse(buf.AsSpan(pos),out uint v,out int bc);pos+=bc;return v;}[凾(256)]public long Long(){FillEntireNumber();TryParse(buf.AsSpan(pos),out long v,out int bc);pos+=bc;return v;}[凾(256)]public ulong ULong(){FillEntireNumber();TryParse(buf.AsSpan(pos),out ulong v,out int bc);pos+=bc;return v;}[凾(256)]public double Double(){FillEntireNumber();TryParse(buf.AsSpan(pos),out double v,out int bc);pos+=bc;return v;}[凾(256)]public decimal Decimal(){FillEntireNumber();TryParse(buf.AsSpan(pos),out decimal v,out int bc);pos+=bc;return v;}[凾(256)]public string String(){var sb=new List();;byte b;do b=ReadByte();while(b<=' ');do{sb.Add(b);b=ReadByte();}while(' '();byte b;do b=ReadByte();while(b<=' ');do{sb.Add(b);b=ReadByte();}while(b!='\n'&&b!='\r');return encoding.GetString(sb.ToArray());}[凾(256)]public char Char(){byte b;do b=ReadByte();while(b<=' ');return(char)b;}[凾(256)]public int Int0()=>Int()-1;[凾(256)]public uint UInt0()=>UInt()-1;[凾(256)]public long Long0()=>Long()-1;[凾(256)]public ulong ULong0()=>ULong()-1;[凾(256)]public static implicit operator int(_R cr)=>cr.Int();[凾(256)]public static implicit operator uint(_R cr)=>cr.UInt();[凾(256)]public static implicit operator long(_R cr)=>cr.Long();[凾(256)]public static implicit operator ulong(_R cr)=>cr.ULong();[凾(256)]public static implicit operator double(_R cr)=>cr.Double();[凾(256)]public static implicit operator decimal(_R cr)=>cr.Decimal();[凾(256)]public static implicit operator string(_R cr)=>cr.Ascii();public T[]Repeat(int count){var arr=new T[count];for(int i=0;i();return arr;}}}
namespace Kzrnm.Competitive.IO{public sealed class PropertyConsoleReader:ConsoleReader{public PropertyConsoleReader():base(){}public PropertyConsoleReader(Stream input,Encoding encoding):base(input,encoding){}public PropertyConsoleReader(Stream input,Encoding encoding,int bufferSize):base(input,encoding,bufferSize){}public new int Int=>Int();public new int Int0=>Int0();public new uint UInt=>UInt();public new uint UInt0=>UInt0();public new long Long=>Long();public new long Long0=>Long0();public new ulong ULong=>ULong();public new ulong ULong0=>ULong0();public new double Double=>Double();public new decimal Decimal=>Decimal();public new string String=>String();public new string Ascii=>Ascii();public new string Line=>Line();public new char Char=>Char();}}
namespace Kzrnm.Competitive.IO{using static Utf8Formatter;using _W=Utf8ConsoleWriter;public sealed class Utf8ConsoleWriter:IDisposable{internal static readonly UTF8Encoding Utf8NoBom=new UTF8Encoding(false);internal const int BufSize=1<<12;internal readonly Stream output;internal byte[]buf;internal int len;public Utf8ConsoleWriter():this(Console.OpenStandardOutput()){}public Utf8ConsoleWriter(Stream output):this(output,BufSize){}public Utf8ConsoleWriter(Stream output,int bufferSize){this.output=output;buf=new byte[bufferSize];}public StreamWriter ToStreamWriter(){Flush();return new StreamWriter(output,Utf8NoBom);}[凾(256)]public void Flush(){output.Write(buf,0,len);len=0;}void IDisposable.Dispose()=>Flush();[凾(256)]private SpanEnsureBuf(int size){if(buf.Length-len(T v){void FormatFloat(double d,out int b)=>TryFormat(d,EnsureBuf(Math.Max(25+(int)Math.Log10(Math.Abs(d)),32)),out b,new StandardFormat('F',20));void FormatDec(decimal d,out int b)=>TryFormat(d,EnsureBuf(Math.Max(25+(int)Math.Log10((double)Math.Abs(d)),32)),out b,new StandardFormat('F',20));int bw;if(typeof(T)==typeof(int))TryFormat((int)(object)v,EnsureBuf(21),out bw);else if(typeof(T)==typeof(long))TryFormat((long)(object)v,EnsureBuf(21),out bw);else if(typeof(T)==typeof(uint))TryFormat((uint)(object)v,EnsureBuf(21),out bw);else if(typeof(T)==typeof(ulong))TryFormat((ulong)(object)v,EnsureBuf(21),out bw);else if(typeof(T)==typeof(short))TryFormat((short)(object)v,EnsureBuf(9),out bw);else if(typeof(T)==typeof(ushort))TryFormat((ushort)(object)v,EnsureBuf(9),out bw);else if(typeof(T)==typeof(byte))TryFormat((byte)(object)v,EnsureBuf(9),out bw);else if(typeof(T)==typeof(sbyte))TryFormat((sbyte)(object)v,EnsureBuf(9),out bw);else if(typeof(T)==typeof(float))FormatFloat((float)(object)v,out bw);else if(typeof(T)==typeof(double))FormatFloat((double)(object)v,out bw);else if(typeof(T)==typeof(decimal))FormatDec((decimal)(object)v,out bw);else if(typeof(T)==typeof(char)){var dst=EnsureBuf(6);var c=(char)(object)v;if(c<0x007f){dst[0]=(byte)c;bw=1;}else{Spans=stackalloc char[1]{c};bw=Utf8NoBom.GetBytes(s,dst);}}else if(v is char[]charr)return Write(charr.AsSpan());else if(v is IUtf8ConsoleWriterFormatter f){f.Write(this);return this;}else return Write(v.ToString().AsSpan());len+=bw;return this;}[凾(256|512)]public _W Write(ReadOnlySpanv){var mlen=Utf8NoBom.GetMaxByteCount(v.Length);if(mlen>buf.Length){Flush();buf=new byte[mlen*2];}else if(mlen>buf.Length-len){Flush();}var bw=Utf8NoBom.GetBytes(v,buf.AsSpan(len));len+=bw;return this;}[凾(256)]public _W WriteLine()=>Write('\n');[凾(256)]public _W WriteLine(T v){Write(v);return Write('\n');}[凾(256)]public _W WriteLine(ReadOnlySpanv){Write(v);return Write('\n');}[凾(256)]public _W WriteLineJoin(IEnumerablecol)=>WriteMany(' ',col);[凾(256)]public _W WriteLineJoin((T1,T2)tuple){Write(tuple.Item1);Write(' ');return WriteLine(tuple.Item2);}[凾(256)]public _W WriteLineJoin((T1,T2,T3)tuple){Write(tuple.Item1);Write(' ');Write(tuple.Item2);Write(' ');return WriteLine(tuple.Item3);}[凾(256)]public _W WriteLineJoin((T1,T2,T3,T4)tuple){Write(tuple.Item1);Write(' ');Write(tuple.Item2);Write(' ');Write(tuple.Item3);Write(' ');return WriteLine(tuple.Item4);}[凾(256)]public _W WriteLineJoin(TTuple tuple)where TTuple:ITuple{var col=new object[tuple.Length];for(int i=0;iWriteMany(' ',col);[凾(256)]public _W WriteLineJoin(T1 v1,T2 v2){Write(v1);Write(' ');return WriteLine(v2);}[凾(256)]public _W WriteLineJoin(T1 v1,T2 v2,T3 v3){Write(v1);Write(' ');Write(v2);Write(' ');return WriteLine(v3);}[凾(256)]public _W WriteLineJoin(T1 v1,T2 v2,T3 v3,T4 v4){Write(v1);Write(' ');Write(v2);Write(' ');Write(v3);Write(' ');return WriteLine(v4);}[凾(256)]public _W WriteLineJoin(params T[]col)=>WriteMany(' ',(ReadOnlySpan)col);[凾(256)]public _W WriteLineJoin(Spancol)=>WriteMany(' ',(ReadOnlySpan)col);[凾(256)]public _W WriteLineJoin(ReadOnlySpancol)=>WriteMany(' ',col);[凾(256)]public _W WriteLines(IEnumerablecol)=>WriteMany('\n',col);[凾(256)]public _W WriteLines(T[]col)=>WriteMany('\n',(ReadOnlySpan)col);[凾(256)]public _W WriteLines(Spancol)=>WriteMany('\n',(ReadOnlySpan)col);[凾(256)]public _W WriteLines(ReadOnlySpancol)=>WriteMany('\n',col);[凾(256)]public _W WriteGrid(IEnumerable>cols){foreach(var col in cols)WriteLineJoin(col);return this;}[凾(256)]public _W WriteGrid(IEnumerabletuples)where TTuple:ITuple{foreach(var tup in tuples)WriteLineJoin(tup);return this;}[凾(256)]private _W WriteMany(char sep,IEnumerablecol){if(col is T[]array)return WriteMany(sep,(ReadOnlySpan)array);var en=col.GetEnumerator();if(en.MoveNext()){Write(en.Current);while(en.MoveNext()){Write(sep);Write(en.Current);}}return WriteLine();}[凾(256)]private _W WriteMany(char sep,ReadOnlySpancol){if(col.Length>0){Write(col[0]);foreach(var c in col.Slice(1)){Write(sep);Write(c);}}return WriteLine();}}public interface IUtf8ConsoleWriterFormatter{void Write(_W cw);}}
namespace Kzrnm.Competitive{using O=ConsoleOutput;public static class ConsoleOutputExt{[凾(256)]public static O ToConsoleOutput(this T f)where T:IUtf8ConsoleWriterFormatter{var cw=O.cw;f.Write(cw);return cw.WriteLine();}}public struct ConsoleOutput{public static Utf8ConsoleWriter cw;public static implicit operator O(int v)=>cw.WriteLine(v);public static implicit operator O(long v)=>cw.WriteLine(v);public static implicit operator O(uint v)=>cw.WriteLine(v);public static implicit operator O(ulong v)=>cw.WriteLine(v);public static implicit operator O(double v)=>cw.WriteLine(v);public static implicit operator O(decimal v)=>cw.WriteLine(v);public static implicit operator O(char v)=>cw.WriteLine(v);public static implicit operator O(ReadOnlySpanv)=>cw.WriteLine(v);public static implicit operator O(char[]v)=>cw.WriteLine((ReadOnlySpan)v);public static implicit operator O(string v)=>cw.WriteLine((ReadOnlySpan)v);public static implicit operator O(bool v)=>cw.WriteLine((ReadOnlySpan)(v?"Yes":"No"));public static implicit operator O(Utf8ConsoleWriter _)=>default;}}
internal partial class Program{public PropertyConsoleReader cr;public Utf8ConsoleWriter cw;public Program(PropertyConsoleReader r,Utf8ConsoleWriter w){cr=r;ConsoleOutput.cw=cw=w;CultureInfo.CurrentCulture=CultureInfo.InvariantCulture;}public void Run(){int Q=__ManyTestCases?cr.Int:1;while( --Q>=0)Calc();cw.Flush();}}
namespace Kzrnm.Competitive{public class SparseTablewhere TOp:struct,ISparseTableOperator{private static TOp op=default;private readonly TValue[][]st;public int Length{get;}public SparseTable(TValue[]array){Length=array.Length;st=new TValue[BitOperations.Log2((uint)Length)+1][];st[0]=(TValue[])array.Clone();for(int i=1;iProd(l,l+length);[凾(256)]public TValue Prod(int l,int r){var b=BitOperations.Log2((uint)(r-l));var stb=st[b];return op.Operate(stb[l],stb[r-(1<st;public DebugView(SparseTablest){this.st=st;}public DebugItem[]Items{get{var items=new List(st.st.Length*st.Length);for(int b=0;b{T Operate(T x,T y);}}
namespace Kzrnm.Competitive{public static class __ArrayExtension{[凾(256)]public static T[]Fill(this T[]arr,T value){arr.AsSpan().Fill(value);return arr;}[凾(256)]public static T[]Sort(this T[]arr){Array.Sort(arr);return arr;}[凾(256)]public static string[]Sort(this string[]arr)=>Sort(arr,StringComparer.Ordinal);[凾(256)]public static T[]Sort(this T[]arr,Funcselector)where U:IComparable{Array.Sort(arr.Select(selector).ToArray(),arr);return arr;}[凾(256)]public static T[]Sort(this T[]arr,Comparisoncomparison){Array.Sort(arr,comparison);return arr;}[凾(256)]public static T[]Sort(this T[]arr,IComparercomparer){Array.Sort(arr,comparer);return arr;}[凾(256)]public static T[]Reverse(this T[]arr){Array.Reverse(arr);return arr;}[凾(256)]public static ref T Get(this T[]arr,int index){if(index<0)index+=arr.Length;return ref arr[index];}[凾(256)]public static ref readonly T GetOrDummy(this ReadOnlySpanarr,int index,T dummy=default){if((uint)index<(uint)arr.Length)return ref arr[index];Dummy.dummy=dummy;return ref Dummy.dummy;}[凾(256)]public static ref T GetOrDummy(this Spanarr,int index,T dummy=default){if((uint)index<(uint)arr.Length)return ref arr[index];Dummy.dummy=dummy;return ref Dummy.dummy;}[凾(256)]public static ref T GetOrDummy(this T[]arr,int index,T dummy=default)=>ref GetOrDummy(arr.AsSpan(),index,dummy);[凾(256)]public static ref T GetOrDummy(this T[][]arr,int index1,int index2,T dummy=default){if((uint)index1<(uint)arr.Length)return ref GetOrDummy(arr[index1],index2,dummy);Dummy.dummy=dummy;return ref Dummy.dummy;}[凾(256)]public static ref T GetOrDummy(this T[][][]arr,int index1,int index2,int index3,T dummy=default){if((uint)index1<(uint)arr.Length)return ref GetOrDummy(arr[index1],index2,index3,dummy);Dummy.dummy=dummy;return ref Dummy.dummy;}private static class Dummy{public static T dummy;}[凾(256)]public static int FindByBinarySearch(this T[]arr,TCv value)where TCv:IComparable =>FindByBinarySearch((ReadOnlySpan)arr,value);[凾(256)]public static int FindByBinarySearch(this Spanarr,TCv value)where TCv:IComparable =>FindByBinarySearch((ReadOnlySpan)arr,value);[凾(256)]public static int FindByBinarySearch(this ReadOnlySpanarr,TCv value)where TCv:IComparable{int ix=arr.BinarySearch(value);if(ix<0)ix=~ix;return ix;}}}
namespace Kzrnm.Competitive{public static class __MemoryMarshalExtension{private class ArrayVal{public T[]arr;}[凾(256)]public static SpanAsSpan(this Listlist,int start=0)=>Unsafe.As>(list).arr.AsSpan(start,list.Count-start);[凾(256)]public static SpanCast(this Spanspan)where TFrom:struct where TTo:struct=>MemoryMarshal.Cast(span);[凾(256)]public static ReadOnlySpanCast(this ReadOnlySpanspan)where TFrom:struct where TTo:struct=>MemoryMarshal.Cast(span);[凾(256)]public static ref T GetReference(this Spanspan)=>ref MemoryMarshal.GetReference(span);[凾(256)]public static ref T GetReference(this ReadOnlySpanspan)=>ref MemoryMarshal.GetReference(span);}}
namespace Kzrnm.Competitive{public static class __CollectionTupleExtension_Stack{[凾(256)]public static bool TryPop(this Stack<(T1,T2)>stack,out T1 item1,out T2 item2){var ok=stack.TryPop(out var tuple);(item1,item2)=tuple;return ok;}[凾(256)]public static bool TryPop(this Stack<(T1,T2,T3)>stack,out T1 item1,out T2 item2,out T3 item3){var ok=stack.TryPop(out var tuple);(item1,item2,item3)=tuple;return ok;}[凾(256)]public static bool TryPeek(this Stack<(T1,T2)>stack,out T1 item1,out T2 item2){var ok=stack.TryPeek(out var tuple);(item1,item2)=tuple;return ok;}[凾(256)]public static bool TryPeek(this Stack<(T1,T2,T3)>stack,out T1 item1,out T2 item2,out T3 item3){var ok=stack.TryPeek(out var tuple);(item1,item2,item3)=tuple;return ok;}}}
namespace Kzrnm.Competitive{public static class Global{[凾(256)]public static string YesNo(bool b)=>b?"Yes":"No";[凾(256)]public static string TakahashiAoki(bool b)=>b?"Takahashi":"Aoki";[凾(256)]public static T[]NewArray(int len0,T value)where T:struct=>new T[len0].Fill(value);[凾(256)]public static T[]NewArray(int len0,Funcfactory){var arr=new T[len0];for(int i=0;i(int len0,int len1,T value)where T:struct{var arr=new T[len0][];for(int i=0;i(int len0,int len1,Funcfactory){var arr=new T[len0][];for(int i=0;i(int len0,int len1,int len2,T value)where T:struct{var arr=new T[len0][][];for(int i=0;i(int len0,int len1,int len2,Funcfactory){var arr=new T[len0][][];for(int i=0;i(int len0,int len1,int len2,int len3,T value)where T:struct{var arr=new T[len0][][][];for(int i=0;i(int len0,int len1,int len2,int len3,Funcfactory){var arr=new T[len0][][][];for(int i=0;iedgeContainer;public GraphBuilder(int size,bool isDirected){edgeContainer=new EdgeContainer(size,isDirected);}public static GraphBuilder Create(int count,ConsoleReader cr,int edgeCount,bool isDirected){var gb=new GraphBuilder(count,isDirected);for(var i=0;iCreateWithEdgeIndex(int count,ConsoleReader cr,int edgeCount,bool isDirected){var gb=new GraphBuilder(count,isDirected);for(var i=0;iedgeContainer.Add(from,new GraphEdge(to));public SimpleGraphToGraph()=>GraphBuilderLogic.ToGraph,GraphNode,GraphEdge,TOp>(edgeContainer);public TreeGraphToTree(int root=0)=>GraphBuilderLogic.ToTree,TreeNode,GraphEdge,TOp>(edgeContainer,root);struct TOp:IGraphBuildOperator,GraphNode,GraphEdge>,ITreeBuildOperator,TreeNode,GraphEdge>{[凾(256)]public SimpleGraphGraph(GraphNode[]nodes,CSRedges)=>new SimpleGraph(nodes,edges);[凾(256)]public GraphNode Node(int i,GraphEdge[]parents,GraphEdge[]children)=>new GraphNode(i,parents,children);[凾(256)]public TreeGraphTree(TreeNode[]nodes,int root,HeavyLightDecompositionhl)=>new TreeGraph(nodes,root,hl);[凾(256)]public TreeNode TreeNode(int i,int size,TreeNode parent,GraphEdge edge,GraphEdge[]children)=>new TreeNode(i,size,edge.Reversed(parent.Index),parent.Depth+1,children);[凾(256)]public TreeNode TreeRootNode(int i,int size,GraphEdge[]children)=>new TreeNode(i,size,GraphEdge.None,0,children);}}public readonly struct GraphEdge:IGraphEdge,IReversable,IEquatable{public static GraphEdge None{get;}=new GraphEdge(-1);public GraphEdge(int to){To=to;}public int To{get;}[凾(256)]public static implicit operator int(GraphEdge e)=>e.To;public override string ToString()=>To.ToString();[凾(256)]public GraphEdge Reversed(int from)=>new GraphEdge(from);public override int GetHashCode()=>To;public override bool Equals(object obj)=>obj is GraphEdge edge&&Equals(edge);public bool Equals(GraphEdge other)=>To==other.To;public static bool operator==(GraphEdge left,GraphEdge right)=>left.Equals(right);public static bool operator!=(GraphEdge left,GraphEdge right)=>!left.Equals(right);}public class GraphNode:IGraphNode,IEquatable{public GraphNode(int i,GraphEdge[]parents,GraphEdge[]children){Index=i;Parents=parents;Children=children;}public int Index{get;}public GraphEdge[]Parents{get;}public GraphEdge[]Children{get;}public bool IsDirected=>Parents!=Children;public override string ToString()=>$"children: {string.Join(",",Children)}";public override bool Equals(object obj)=>obj is GraphNode d&&Equals(d);public bool Equals(GraphNode other)=>Index==other?.Index;public override int GetHashCode()=>Index;}public class TreeNode:ITreeNode,IEquatable{public TreeNode(int i,int size,GraphEdge parent,int depth,GraphEdge[]children){Index=i;Parent=parent;Children=children;Depth=depth;Size=size;}public int Index{get;}public GraphEdge Parent{get;}public GraphEdge[]Children{get;}public int Depth{get;}public int Size{get;}public override string ToString()=>$"children: {string.Join(",",Children)}";public override bool Equals(object obj)=>obj is TreeNode node&&Equals(node);public bool Equals(TreeNode other)=>other!=null&&Index==other.Index;public override int GetHashCode()=>Index;}}
namespace Kzrnm.Competitive{public class GraphBuilder{internal readonly EdgeContainer>edgeContainer;public GraphBuilder(int size,bool isDirected){edgeContainer=new EdgeContainer>(size,isDirected);}[凾(256)]public void Add(int from,int to,T data)=>edgeContainer.Add(from,new GraphEdge(to,data));public SimpleGraph>,GraphEdge>ToGraph()=>GraphBuilderLogic.ToGraph>,GraphEdge>,GraphNode>,GraphEdge,TOp>(edgeContainer);public TreeGraph,GraphEdge>ToTree(int root=0)=>GraphBuilderLogic.ToTree,GraphEdge>,TreeNode,GraphEdge,TOp>(edgeContainer,root);struct TOp:IGraphBuildOperator>,GraphEdge>,GraphNode>,GraphEdge>,ITreeBuildOperator,GraphEdge>,TreeNode,GraphEdge>{[凾(256)]public SimpleGraph>,GraphEdge>Graph(GraphNode>[]nodes,CSR>edges)=>new SimpleGraph>,GraphEdge>(nodes,edges);[凾(256)]public GraphNode>Node(int i,GraphEdge[]parents,GraphEdge[]children)=>new GraphNode>(i,parents,children);[凾(256)]public TreeGraph,GraphEdge>Tree(TreeNode[]nodes,int root,HeavyLightDecomposition,GraphEdge>hl)=>new TreeGraph,GraphEdge>(nodes,root,hl);[凾(256)]public TreeNodeTreeNode(int i,int size,TreeNodeparent,GraphEdgeedge,GraphEdge[]children)=>new TreeNode(i,size,edge.Reversed(parent.Index),parent.Depth+1,children);[凾(256)]public TreeNodeTreeRootNode(int i,int size,GraphEdge[]children)=>new TreeNode(i,size,GraphEdge.None,0,children);}}public readonly struct GraphEdge:IGraphEdge,IGraphData,IReversable>,IEquatable>{public static GraphEdgeNone{get;}=new GraphEdge(-1,default);public GraphEdge(int to,T data){To=to;Data=data;}public T Data{get;}public int To{get;}[凾(256)]public static implicit operator int(GraphEdgee)=>e.To;public override string ToString()=>$"to:{To}, Data:{Data}";[凾(256)]public void Deconstruct(out int to,out T data){to=To;data=Data;}[凾(256)]public GraphEdgeReversed(int from)=>new GraphEdge(from,Data);public override int GetHashCode()=>To;public override bool Equals(object obj)=>obj is GraphEdgeedge&&Equals(edge);public bool Equals(GraphEdgeother)=>To==other.To;public static bool operator==(GraphEdgeleft,GraphEdgeright)=>left.Equals(right);public static bool operator!=(GraphEdgeleft,GraphEdgeright)=>!left.Equals(right);}public class GraphNode:IGraphNode,IEquatable