結果

問題 No.1153 ねこちゃんゲーム
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-08-08 03:10:02
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,994 bytes
コンパイル時間 1,632 ms
コンパイル使用メモリ 114,056 KB
実行使用メモリ 93,536 KB
最終ジャッジ日時 2023-10-25 21:13:31
合計ジャッジ時間 42,448 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
24,224 KB
testcase_01 AC 25 ms
24,132 KB
testcase_02 AC 32 ms
25,028 KB
testcase_03 AC 33 ms
25,036 KB
testcase_04 AC 32 ms
25,028 KB
testcase_05 AC 32 ms
25,036 KB
testcase_06 AC 34 ms
25,028 KB
testcase_07 AC 675 ms
75,196 KB
testcase_08 AC 667 ms
75,200 KB
testcase_09 AC 676 ms
75,200 KB
testcase_10 AC 667 ms
75,200 KB
testcase_11 AC 723 ms
75,208 KB
testcase_12 AC 691 ms
75,200 KB
testcase_13 AC 695 ms
75,188 KB
testcase_14 AC 785 ms
75,196 KB
testcase_15 AC 738 ms
75,200 KB
testcase_16 AC 696 ms
75,204 KB
testcase_17 AC 697 ms
75,396 KB
testcase_18 AC 703 ms
75,384 KB
testcase_19 AC 695 ms
75,396 KB
testcase_20 AC 694 ms
75,440 KB
testcase_21 AC 698 ms
75,444 KB
testcase_22 AC 688 ms
75,204 KB
testcase_23 AC 690 ms
75,404 KB
testcase_24 AC 692 ms
75,396 KB
testcase_25 AC 714 ms
75,592 KB
testcase_26 AC 693 ms
75,364 KB
testcase_27 AC 770 ms
92,964 KB
testcase_28 AC 743 ms
84,996 KB
testcase_29 AC 735 ms
88,756 KB
testcase_30 AC 737 ms
88,548 KB
testcase_31 AC 745 ms
93,536 KB
testcase_32 AC 657 ms
77,924 KB
testcase_33 AC 653 ms
77,920 KB
testcase_34 AC 637 ms
77,924 KB
testcase_35 AC 643 ms
77,920 KB
testcase_36 AC 655 ms
77,076 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;
		g[o]=h[o];
		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