結果

問題 No.1153 ねこちゃんゲーム
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-08-08 02:50:04
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,981 bytes
コンパイル時間 1,171 ms
コンパイル使用メモリ 114,148 KB
実行使用メモリ 93,556 KB
最終ジャッジ日時 2023-10-25 10:31:38
合計ジャッジ時間 39,771 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,276 KB
testcase_01 AC 25 ms
24,176 KB
testcase_02 AC 34 ms
25,060 KB
testcase_03 AC 34 ms
25,068 KB
testcase_04 AC 34 ms
25,060 KB
testcase_05 WA -
testcase_06 AC 34 ms
25,060 KB
testcase_07 AC 817 ms
75,216 KB
testcase_08 AC 827 ms
75,220 KB
testcase_09 WA -
testcase_10 AC 836 ms
75,220 KB
testcase_11 AC 827 ms
75,228 KB
testcase_12 AC 828 ms
75,224 KB
testcase_13 AC 830 ms
75,220 KB
testcase_14 AC 820 ms
75,216 KB
testcase_15 AC 813 ms
75,220 KB
testcase_16 AC 817 ms
75,224 KB
testcase_17 AC 828 ms
75,420 KB
testcase_18 AC 814 ms
75,408 KB
testcase_19 AC 848 ms
75,420 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 839 ms
75,224 KB
testcase_23 WA -
testcase_24 AC 835 ms
75,420 KB
testcase_25 WA -
testcase_26 AC 840 ms
75,388 KB
testcase_27 AC 884 ms
92,984 KB
testcase_28 AC 881 ms
85,016 KB
testcase_29 AC 867 ms
88,776 KB
testcase_30 AC 887 ms
88,568 KB
testcase_31 AC 897 ms
93,556 KB
testcase_32 AC 741 ms
77,944 KB
testcase_33 AC 758 ms
77,940 KB
testcase_34 AC 766 ms
77,944 KB
testcase_35 AC 758 ms
77,940 KB
testcase_36 AC 770 ms
77,100 KB
testcase_37 TLE -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static List<int>[] li;
	static List<int>[] lih;
	static bool[] b;
	static int[] h,d,oa,g;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int n=s[0],m=n-1;
		if(n==1){
			Console.WriteLine("-1 -1");
			return;
		}
		li=new List<int>[n+1];
		lih=new List<int>[n+1];
		b=new bool[n+1];
		h=new int[n+1];
		g=new int[n+1];
		d=new int[n+1];
		oa=new int[n+1];
		var a=sc.Ia;
		for(int i=1;i<=n;i++){
			li[i]=new List<int>();
			lih[i]=new List<int>();
		}
		for(int i=0;i<m;i++){
			var e=sc.Ia;
			li[e[0]].Add(e[1]);
			li[e[1]].Add(e[0]);
		}
		int o=1;
		for(int i = 1;i<=n;i++) {
			if(li[i].Count==1){
				o=i;
				break;
			}
		}
		Fu(o,0);
		b=new bool[n+1];
		h[0]=mod;
		Fu2(li[o][0],0);
		int ans=0;
		for(int i = 0;i<s[1];i++) {ans^=g[a[i]];}
		if(ans==0){Console.WriteLine("-1 -1");}
		else{
			for(int i = 0;i<s[1];i++) {
				if(oa[a[i]]!=0&&(ans^g[a[i]]^d[a[i]])==0){
					Console.WriteLine("{0} {1}",i+1,oa[a[i]]);
					return;
				}
				for(int j = 0;j<lih[a[i]].Count;j++) {
					if(lih[a[i]][j]==0){break;}
					if((ans^g[a[i]]^h[lih[a[i]][j]])==0){
						Console.WriteLine("{0} {1}",i+1,lih[a[i]][j]);
						return;
					}
				}
			}
		}
	}
	static void Fu2(int a,int p){
		lih[a].Sort((u,v)=>h[u]-h[v]);
		lih[a].Add(0);
		d[a]=p;
		int z=p==0?1:0;

		for(int i = 0;i<lih[a].Count;i++) {
			if(z==p){z++;}
			if(h[lih[a][i]]==z){z++;}
			else if(h[lih[a][i]]>z){
				break;
			}
		}
		g[a]=z;
		for(int i = 0;i<lih[a].Count;i++) {
			z=h[lih[a][i]];
			if(z==p){z=g[a];}
			else if(i!=0&&z==h[lih[a][i-1]]){z=g[a];}
			else if(i!=lih[a].Count-1&&z==h[lih[a][i+1]]){z=g[a];}
			if(lih[a][i]!=0){
				Fu2(lih[a][i],Min(z,g[a]));
			}
		}
	}
	static void Fu(int a,int p){
		b[a]=true;
		oa[a]=p;
		for(int i=0;i<li[a].Count;i++){
			if(!b[li[a][i]]){
				Fu(li[a][i],a);
				lih[a].Add(li[a][i]);
			}
		}
		for(int i = 0;i<lih[a].Count;i++) {d[h[lih[a][i]]]=a;}
		for(int i = 0;;i++) {
			if(d[i]!=a){
				h[a]=i;
				break;
			}
		}
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
0