結果

問題 No.2822 Lights Up! (Tree Edition)
ユーザー KumaTachiRenKumaTachiRen
提出日時 2024-07-26 21:53:29
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 7,330 bytes
コンパイル時間 8,475 ms
コンパイル使用メモリ 165,840 KB
実行使用メモリ 182,712 KB
最終ジャッジ日時 2024-07-26 21:53:49
合計ジャッジ時間 19,314 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
22,784 KB
testcase_01 AC 43 ms
22,912 KB
testcase_02 AC 75 ms
32,256 KB
testcase_03 WA -
testcase_04 AC 74 ms
32,384 KB
testcase_05 AC 75 ms
32,640 KB
testcase_06 AC 74 ms
32,384 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 73 ms
32,640 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 66 ms
28,928 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 45 ms
23,040 KB
testcase_18 WA -
testcase_19 AC 48 ms
24,832 KB
testcase_20 AC 45 ms
23,168 KB
testcase_21 WA -
testcase_22 AC 50 ms
25,088 KB
testcase_23 AC 51 ms
24,832 KB
testcase_24 AC 49 ms
25,072 KB
testcase_25 WA -
testcase_26 AC 50 ms
24,960 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 44 ms
23,040 KB
testcase_32 AC 53 ms
26,240 KB
testcase_33 AC 53 ms
26,096 KB
testcase_34 WA -
testcase_35 AC 53 ms
25,984 KB
testcase_36 WA -
testcase_37 AC 52 ms
25,856 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 53 ms
25,856 KB
testcase_42 AC 53 ms
26,112 KB
testcase_43 AC 53 ms
25,856 KB
testcase_44 AC 53 ms
25,856 KB
testcase_45 AC 53 ms
25,984 KB
testcase_46 AC 53 ms
25,856 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 43 ms
22,912 KB
testcase_52 AC 43 ms
23,040 KB
testcase_53 WA -
testcase_54 AC 43 ms
23,040 KB
testcase_55 WA -
testcase_56 AC 43 ms
22,912 KB
testcase_57 AC 43 ms
22,912 KB
testcase_58 AC 43 ms
23,040 KB
testcase_59 AC 42 ms
23,168 KB
testcase_60 AC 43 ms
22,784 KB
testcase_61 WA -
testcase_62 WA -
testcase_63 AC 42 ms
23,040 KB
testcase_64 AC 43 ms
23,168 KB
testcase_65 AC 43 ms
22,912 KB
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 AC 43 ms
22,784 KB
testcase_72 WA -
testcase_73 WA -
testcase_74 AC 43 ms
22,784 KB
testcase_75 AC 42 ms
23,136 KB
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 AC 43 ms
23,296 KB
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 42 ms
22,656 KB
testcase_83 WA -
testcase_84 AC 43 ms
22,912 KB
testcase_85 AC 43 ms
22,784 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 AC 43 ms
23,012 KB
testcase_89 AC 43 ms
22,912 KB
testcase_90 WA -
testcase_91 WA -
testcase_92 AC 41 ms
22,656 KB
testcase_93 WA -
testcase_94 WA -
testcase_95 AC 42 ms
23,040 KB
testcase_96 AC 41 ms
22,908 KB
testcase_97 AC 42 ms
23,028 KB
testcase_98 WA -
testcase_99 AC 42 ms
22,896 KB
testcase_100 WA -
testcase_101 WA -
testcase_102 WA -
testcase_103 AC 42 ms
22,912 KB
testcase_104 AC 42 ms
23,040 KB
testcase_105 WA -
testcase_106 WA -
testcase_107 WA -
testcase_108 WA -
testcase_109 WA -
testcase_110 WA -
testcase_111 WA -
testcase_112 AC 44 ms
22,912 KB
testcase_113 AC 43 ms
22,896 KB
testcase_114 WA -
testcase_115 WA -
testcase_116 AC 43 ms
23,168 KB
testcase_117 AC 42 ms
23,168 KB
testcase_118 AC 43 ms
22,784 KB
testcase_119 AC 42 ms
23,140 KB
testcase_120 WA -
testcase_121 WA -
testcase_122 WA -
testcase_123 AC 42 ms
22,656 KB
testcase_124 WA -
testcase_125 WA -
testcase_126 AC 43 ms
23,028 KB
testcase_127 WA -
testcase_128 AC 42 ms
23,028 KB
testcase_129 WA -
testcase_130 WA -
testcase_131 AC 43 ms
22,912 KB
testcase_132 WA -
testcase_133 AC 42 ms
23,168 KB
testcase_134 AC 43 ms
22,912 KB
testcase_135 WA -
testcase_136 AC 44 ms
22,784 KB
testcase_137 WA -
testcase_138 AC 43 ms
22,912 KB
testcase_139 AC 44 ms
22,656 KB
testcase_140 AC 43 ms
23,152 KB
testcase_141 AC 42 ms
23,152 KB
testcase_142 AC 43 ms
22,656 KB
testcase_143 AC 43 ms
182,712 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (96 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using Lib;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static Lib.OutputLib;
public class Solver
{
    const bool MultiTestCase = false;
    void Solve()
    {
        int n = ri;
        var p = new int[n];
        p[0] = -1;
        for (int i = 1; i < n; i++) p[i] = ri - 1;
        var s = "_" + rs;

        var a = new int[n];
        for (int i = 1; i < n; i++)
        {
            a[i] = a[p[i]];
            if (s[i] == '#') a[i] ^= 1;
        }


        int k = ri;
        var qs = new (int u, int v)[k];
        for (int i = 0; i < k; i++) qs[i] = (ri - 1, ri - 1);

        var uf = new UnionFind(n);
        foreach (var (u, v) in qs) uf.Unite(u, v);

        bool ans = true;
        var gs = uf.GetGroups();
        foreach (var g in gs)
        {
            int r = g[0];
            if (uf.IsSame(r, 0)) continue;
            int c = 0;
            foreach (var x in g) c ^= a[x];
            ans &= c == 0;
        }
        Yn(ans);
    }

#pragma warning disable CS0162
    public Solver() { if (!MultiTestCase) Solve(); else for (int t = ri; t > 0; t--) Solve(); }
#pragma warning restore CS0162

    const int IINF = 1 << 30;
    const long INF = 1L << 60;
    int ri { [MethodImpl(256)] get => (int)sc.Integer(); }
    long rl { [MethodImpl(256)] get => sc.Integer(); }
    uint rui { [MethodImpl(256)] get => (uint)sc.UInteger(); }
    ulong rul { [MethodImpl(256)] get => sc.UInteger(); }
    double rd { [MethodImpl(256)] get => sc.Double(); }
    string rs { [MethodImpl(256)] get => sc.Scan(); }
    string rline { [MethodImpl(256)] get => sc.Line(); }
    public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
    void ReadArray(out int[] a, int n) { a = new int[n]; for (int i = 0; i < a.Length; i++) a[i] = ri; }
    void ReadArray(out long[] a, int n) { a = new long[n]; for (int i = 0; i < a.Length; i++) a[i] = rl; }
    void ReadArray<T>(out T[] a, int n, Func<T> read) { a = new T[n]; for (int i = 0; i < a.Length; i++) a[i] = read(); }
    void ReadArray<T>(out T[] a, int n, Func<int, T> read) { a = new T[n]; for (int i = 0; i < a.Length; i++) a[i] = read(i); }
}

static class Program
{
    static public void Main(string[] args)
    {
        SourceExpander.Expander.Expand();
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver();
        Console.Out.Flush();
    }
}
#region Expanded by https://github.com/kzrnm/SourceExpander
public class UnionFind{int n;int[]p,sz;public int GroupCount{get;private set;}public UnionFind(int _n){n=_n;GroupCount=n;p=new int[n];sz=new int[n];for(int i=0;i<n;i++){p[i]=i;sz[i]=1;}}public void Clear(){for(int i=0;i<n;i++){p[i]=i;sz[i]=1;}}public int Root(int x){if(p[x]==x)return x;return p[x]=Root(p[x]);}public int Size(int x)=>sz[Root(x)];public bool IsSame(int x,int y)=>Root(x)==Root(y);public bool Unite(int x,int y){int rx=Root(x),ry=Root(y);if(rx==ry)return false;p[ry]=rx;sz[rx]+=sz[ry];GroupCount--;return true;}public int[][]GetGroups(){var leader_buf=new int[n];var group_size=new int[n];int group_count=0;for(int i=0;i<n;i++){leader_buf[i]=Root(i);if(leader_buf[i]==i)group_count++;group_size[leader_buf[i]]++;}var result=new int[n][];for(int i=0;i<n;i++)result[i]=new int[group_size[i]];var idx=new int[n];for(int i=0;i<n;i++)result[leader_buf[i]][idx[leader_buf[i]]++]=i;var res=new int[group_count][];for(int i=0,j=0;i<n;i++)if(leader_buf[i]==i)res[j++]=result[i];return res;}}
namespace Lib{public partial class StreamScanner{public int[][]ReadUnweightedTree(int n,int origin=1){var gr=new List<int>[n];for(int i=0;i<n;i++)gr[i]=new List<int>();for(int i=0;i<n-1;i++){int u=(int)(Integer()-origin);int v=(int)(Integer()-origin);gr[u].Add(v);gr[v].Add(u);}var g=new int[n][];for(int i=0;i<n;i++)g[i]=gr[i].ToArray();return g;}}}
namespace Lib{public partial class StreamScanner{public StreamScanner(Stream stream){str=stream;}private readonly Stream str;private readonly byte[]buf=new byte[1024];private int len,ptr;public bool isEof=false;public bool IsEndOfStream{get{return isEof;}}[MethodImpl(256)]private byte Read(){if(isEof)throw new EndOfStreamException();if(ptr>=len){ptr=0;if((len=str.Read(buf,0,1024))<=0){isEof=true;return 0;}}return buf[ptr++];}[MethodImpl(256)]public char Char(){byte b=0;do b=Read();while(b<33||126<b);return(char)b;}[MethodImpl(256)]public string Line(){var sb=new StringBuilder();for(var b=Char();b!=10&&!isEof;b=(char)Read())sb.Append(b);return sb.ToString();}[MethodImpl(256)]public string Scan(){var sb=new StringBuilder();for(var b=Char();b>=33&&b<=126;b=(char)Read())sb.Append(b);return sb.ToString();}[MethodImpl(256)]public long Integer(){long ret=0;byte b=0;var ng=false;do b=Read();while(b!='-'&&(b<'0'||'9'<b));if(b=='-'){ng=true;b=Read();}for(;true;b=Read()){if(b<'0'||'9'<b)return ng?-ret:ret;else ret=ret*10+b-'0';}}[MethodImpl(256)]public ulong UInteger(){ulong ret=0;byte b=0;do b=Read();while(b<'0'||'9'<b);for(;true;b=Read()){if(b<'0'||'9'<b)return ret;else ret=ret*10+b-'0';}}[MethodImpl(256)]public double Double()=>double.Parse(Scan());}}
namespace Lib{public static class OutputLib{[MethodImpl(256)]public static void WriteJoin<T>(string s,IEnumerable<T>t)=>Console.WriteLine(string.Join(s,t));[MethodImpl(256)]public static void WriteMat<T>(T[,]a,string sep=" "){int sz1=a.GetLength(0),sz2=a.GetLength(1);var b=new T[sz2];for(int i=0;i<sz1;i++){for(int j=0;j<sz2;j++)b[j]=a[i,j];WriteJoin(sep,b);}}[MethodImpl(256)]public static void WriteMat<T>(T[][]a,string sep=" "){for(int i=0;i<a.Length;i++)WriteJoin(sep,a[i]);}[MethodImpl(256)]public static void WriteMat<T>(T[][]a,Func<T,string>map,string sep=" "){for(int i=0;i<a.Length;i++)WriteJoin(sep,a[i].Select(x=>map(x)));}[MethodImpl(256)]public static void Write(object t)=>Console.WriteLine(t.ToString());[MethodImpl(256)]public static void Write(params object[]arg)=>Console.WriteLine(string.Join(" ",arg.Select(x=>x.ToString())));[MethodImpl(256)]public static void Write(string str)=>Console.WriteLine(str);[MethodImpl(256)]public static void WriteFlush(object t){Console.WriteLine(t.ToString());Console.Out.Flush();}[MethodImpl(256)]public static void WriteError(object t)=>Console.Error.WriteLine(t.ToString());[MethodImpl(256)]public static void Flush()=>Console.Out.Flush();[MethodImpl(256)]public static void YN(bool t)=>Console.WriteLine(t?"YES":"NO");[MethodImpl(256)]public static void Yn(bool t)=>Console.WriteLine(t?"Yes":"No");[MethodImpl(256)]public static void yn(bool t)=>Console.WriteLine(t?"yes":"no");[MethodImpl(256)]public static void DeleteLine()=>Console.Write("\x1b[1A\x1b[2K");[MethodImpl(256)]public static void ProgressBar(long now,long total,int blocks=50){int x=(int)((2*now*blocks+1)/(2*total));Console.Write($"\x1b[G[\x1b[42m{string.Concat(Enumerable.Repeat("_",x))}\x1b[0m{string.Concat(Enumerable.Repeat("_",blocks-x))}] : {now} / {total}");}}}
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
0