Submission #66689926


Source Code Expand

using AtCoder.Internal;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
class Program
{
    static void Main()
    {
        SourceExpander.Expander.Expand();

        int N, Q;
        {
            int[] vs = Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray();
            N = vs[0];
            Q = vs[1];
        }

        AtCoder.Dsu dsu = new AtCoder.Dsu(N);
        for (int i = 0; i < Q; i++)
        {
            int[] vs = Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray();
            int t = vs[0];
            int u = vs[1];
            int v = vs[2];
            if (t == 0)
                dsu.Merge(u, v);
            if (t == 1)
                Console.WriteLine(dsu.Same(u, v) ? 1 : 0);
        }
    }
}

#region Expanded by https://github.com/kzrnm/SourceExpander
namespace AtCoder{public class Dsu{public readonly int[]_ps;public Dsu(int n){_ps=new int[n];_ps.AsSpan().Fill(-1);}[MethodImpl(256)]public int Merge(int a,int b){int x=Leader(a),y=Leader(b);if(x==y)return x;if(-_ps[x]<-_ps[y])(x,y)=(y,x);_ps[x]+=_ps[y];_ps[y]=x;return x;}[MethodImpl(256)]public bool Same(int a,int b){return Leader(a)==Leader(b);}[MethodImpl(256)]public int Leader(int a){if(_ps[a]<0)return a;while(0<=_ps[_ps[a]]){(a,_ps[a])=(_ps[a],_ps[_ps[a]]);}return _ps[a];}[MethodImpl(256)]public int Size(int a){return-_ps[Leader(a)];}[MethodImpl(256)]public int[][]Groups(){int n=_ps.Length;int[]leaderBuf=new int[n];int[]id=new int[n];var resultList=new SimpleList<int[]>(n);for(int i=0;i<leaderBuf.Length;i++){leaderBuf[i]=Leader(i);if(i==leaderBuf[i]){id[i]=resultList.Count;resultList.Add(new int[-_ps[i]]);}}var result=resultList.ToArray();int[]ind=new int[result.Length];for(int i=0;i<leaderBuf.Length;i++){var leaderID=id[leaderBuf[i]];result[leaderID][ind[leaderID]]=i;ind[leaderID]++;}return result;}}}
namespace AtCoder.Internal{public class SimpleList<T>:IList<T>,IReadOnlyList<T>{public 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(IEnumerable<T>collection){if(collection is ICollection<T>col){data=new T[col.Count];col.CopyTo(data,0);Count=col.Count;}else{data=new T[DefaultCapacity];foreach(var item in collection)Add(item);}}[MethodImpl(256)]public Memory<T>AsMemory()=>new Memory<T>(data,0,Count);[MethodImpl(256)]public Span<T>AsSpan()=>new Span<T>(data,0,Count);public ref T this[int index]{[MethodImpl(256)]get{if((uint)index>=(uint)Count)ThrowIndexOutOfRangeException();return ref data[index];}}public int Count{get;private set;}[MethodImpl(256)]public void Add(T item){if((uint)Count>=(uint)data.Length)Array.Resize(ref data,data.Length<<1);data[Count++]=item;}[MethodImpl(256)]public void RemoveLast(){if( --Count<0)ThrowIndexOutOfRangeException();}[MethodImpl(256)]public void RemoveLast(int size){if((Count-=size)<0)ThrowIndexOutOfRangeException();}[MethodImpl(256)]public SimpleList<T>Reverse(){Array.Reverse(data,0,Count);return this;}[MethodImpl(256)]public SimpleList<T>Reverse(int index,int count){Array.Reverse(data,index,count);return this;}[MethodImpl(256)]public SimpleList<T>Sort(){Array.Sort(data,0,Count);return this;}[MethodImpl(256)]public SimpleList<T>Sort(IComparer<T>comparer){Array.Sort(data,0,Count,comparer);return this;}[MethodImpl(256)]public SimpleList<T>Sort(int index,int count,IComparer<T>comparer){Array.Sort(data,index,count,comparer);return this;}[MethodImpl(256)]public void Clear()=>Count=0;[MethodImpl(256)]public bool Contains(T item)=>IndexOf(item)>=0;[MethodImpl(256)]public int IndexOf(T item)=>Array.IndexOf(data,item,0,Count);[MethodImpl(256)]public void CopyTo(T[]array,int arrayIndex)=>Array.Copy(data,0,array,arrayIndex,Count);[MethodImpl(256)]public T[]ToArray()=>AsSpan().ToArray();bool ICollection<T>.IsReadOnly=>false;T IList<T>.this[int index]{get=>data[index];set=>data[index]=value;}T IReadOnlyList<T>.this[int index]{get=>data[index];}void IList<T>.Insert(int index,T item)=>throw new NotSupportedException();bool ICollection<T>.Remove(T item)=>throw new NotSupportedException();void IList<T>.RemoveAt(int index)=>throw new NotSupportedException();IEnumerator IEnumerable.GetEnumerator()=>((IEnumerable<T>)this).GetEnumerator();IEnumerator<T>IEnumerable<T>.GetEnumerator(){for(int i=0;i<Count;i++)yield return data[i];}[MethodImpl(256)]public Span<T>.Enumerator GetEnumerator()=>AsSpan().GetEnumerator();private static void ThrowIndexOutOfRangeException()=>throw new IndexOutOfRangeException();}}
namespace SourceExpander{public class Expander{[Conditional("EXP")]public static void Expand(string inputFilePath=null,string outputFilePath=null,bool ignoreAnyError=true){}public static string ExpandString(string inputFilePath=null,bool ignoreAnyError=true){return "";}}}
#endregion Expanded by https://github.com/kzrnm/SourceExpander

Submission Info

Submission Time
Task A - Disjoint Set Union
User hatodemowakaru
Language C# 11.0 AOT (.NET 7.0.7)
Score 100
Code Size 5004 Byte
Status AC
Exec Time 282 ms
Memory 35332 KiB

Compile Error

/judge/Main.cs(37,1132): warning CS0436: The type 'SimpleList<T>' in '/judge/Main.cs' conflicts with the imported type 'SimpleList<T>' in 'ac-library-csharp, Version=3.0.0.8, Culture=neutral, PublicKeyToken=847e4ce792c4cf3a'. Using the type defined in '/judge/Main.cs'. [/judge/Main.csproj]
/judge/Main.cs(37,1220): warning CS0436: The type 'SimpleList<T>' in '/judge/Main.cs' conflicts with the imported type 'SimpleList<T>' in 'ac-library-csharp, Version=3.0.0.8, Culture=neutral, PublicKeyToken=847e4ce792c4cf3a'. Using the type defined in '/judge/Main.cs'. [/judge/Main.csproj]
/judge/Main.cs(37,1331): warning CS0436: The type 'SimpleList<T>' in '/judge/Main.cs' conflicts with the imported type 'SimpleList<T>' in 'ac-library-csharp, Version=3.0.0.8, Culture=neutral, PublicKeyToken=847e4ce792c4cf3a'. Using the type defined in '/judge/Main.cs'. [/judge/Main.csproj]
/judge/Main.cs(37,1413): warning CS0436: The type 'SimpleList<T>' in '/judge/Main.cs' conflicts with the imported type 'SimpleList<T>' in 'ac-library-csharp, Version=3.0.0.8, Culture=neutral, PublicKeyToken=847e4ce792c4cf3a'. Using the type defined in '/judge/Main.cs'. [/judge/Main.csproj]
/judge/Main.cs(37,1524): warning CS0436: The type 'SimpleList<T>' in '/judge/Main.cs' conflicts with the imported type 'SimpleList<T>' in 'ac-library-csharp, Version=3.0.0.8, Culture=neutral, PublicKeyToken=847e4ce792c4cf3a'. Using the type defined in '/judge/Main.cs'. [/judge/Main.csproj]
/judge/Main.cs(20,17): warning CS0436: The type 'Dsu' in '/judge/Main.cs' conflicts with the imported type 'Dsu' in 'ac-library-csharp, Version=3.0.0.8, Culture=neutral, PublicKeyToken=847e4ce792c4cf3a'. Using the type defined in '/judge/Main.cs'. [/judge/Main.csproj]
/judge/Main.cs(20,39): warning CS0436: The type 'Dsu' in '/judge/Main.cs' conflicts with the imported type 'Dsu' in 'ac-library-csharp, Version=3.0.0.8, Culture=neutral, PublicKeyToken=847e4ce792c4cf3a'. Using the type defined in '/judge/Main.cs'. [/judge/Main.csproj]
/judge/Main.cs(36,667): warning CS0436: The type 'SimpleList<T>' in '/judge/Main.cs' conflicts with the imported type 'SimpleList<T>' in 'ac-library-csharp, Version=3.0.0.8, Culture=neutral, PublicKeyToken=847e4ce792c4cf3a'. Using the type defined in '/judge/Main.cs'. [/judge/Main.csproj]

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 1
AC × 11
Set Name Test Cases
Sample example_00
All example_00, random_00, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09
Case Name Status Exec Time Memory
example_00 AC 2 ms 6492 KiB
random_00 AC 221 ms 34872 KiB
random_01 AC 222 ms 35284 KiB
random_02 AC 177 ms 34660 KiB
random_03 AC 49 ms 14244 KiB
random_04 AC 150 ms 33052 KiB
random_05 AC 210 ms 34856 KiB
random_06 AC 171 ms 35332 KiB
random_07 AC 27 ms 10068 KiB
random_08 AC 80 ms 19832 KiB
random_09 AC 282 ms 34924 KiB