Submission #3370572
Source Code Expand
using System; using System.Linq;//リストの使用 using System.Collections.Generic; class Program { static string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。 static long n = long.Parse(input[0]); static long m = long.Parse(input[1]); static long[] parents = new long[n]; static void Main() { for(long i = 1; i < n; i++) { parents[i] = i; } bool answer = true; long peopleMemo = 0; long languageSum = 0; long[][] languageMemoSub = new long[100000][];//言語番号と、話し手番号 for(long i = 0; i < 100000; i++) { languageMemoSub[i] = new long[2]; } for(long i = 0; i < n; i++) { long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse); for(long j = 0; j < nums[0]; j++) { languageMemoSub[languageSum][0] = nums[j+1]; languageMemoSub[languageSum][1] = i; languageSum++; } } long[][] languageMemo = new long[languageSum][];//言語番号と、話し手番号 for(long i = 0; i < languageSum; i++) { languageMemo[i] = new long[2]; languageMemo[i][0] = languageMemoSub[i][0]; languageMemo[i][1] = languageMemoSub[i][1]; } Array.Sort(languageMemo, (a, b) => a[0].CompareTo(b[0]));//言語でソート peopleMemo = languageMemo[0][0]; for(long i = 1; i < languageSum; i++) { if(languageMemo[i][0] == peopleMemo && whatParent(languageMemo[i-1][1]) != whatParent(languageMemo[i][1])) { parents[whatParent(languageMemo[i-1][1])] = whatParent(languageMemo[i][1]);//親を結合して統一。 }else { peopleMemo = languageMemo[i][0]; } } for(long i = 1; i < n; i++) { if(whatParent(0) != whatParent(i)) { answer = false; break; } } Console.WriteLine((answer) ? "YES" : "NO"); } static long whatParent(long child) { if(parents[child] == child) return child; else return parents[child] = whatParent(parents[child]); } }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | suikameron |
Language | C# (Mono 4.6.2.0) |
Score | 400 |
Code Size | 2170 Byte |
Status | AC |
Exec Time | 150 ms |
Memory | 33992 KB |
Judge Result
Set Name | sample | dataset1 | dataset2 | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 200 / 200 | 200 / 200 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt |
dataset1 | sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt |
dataset2 | sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, sample-01.txt, sample-02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 29 ms | 20064 KB |
01-02.txt | AC | 29 ms | 20064 KB |
01-03.txt | AC | 29 ms | 20304 KB |
01-04.txt | AC | 29 ms | 18256 KB |
01-05.txt | AC | 30 ms | 24160 KB |
01-06.txt | AC | 29 ms | 18016 KB |
01-07.txt | AC | 29 ms | 22112 KB |
01-08.txt | AC | 29 ms | 20064 KB |
01-09.txt | AC | 29 ms | 18016 KB |
01-10.txt | AC | 30 ms | 22352 KB |
02-01.txt | AC | 105 ms | 23380 KB |
02-02.txt | AC | 144 ms | 25284 KB |
02-03.txt | AC | 107 ms | 22612 KB |
02-04.txt | AC | 140 ms | 24008 KB |
02-05.txt | AC | 150 ms | 25796 KB |
02-06.txt | AC | 134 ms | 24008 KB |
02-07.txt | AC | 147 ms | 23876 KB |
02-08.txt | AC | 132 ms | 25792 KB |
02-09.txt | AC | 140 ms | 30140 KB |
02-10.txt | AC | 113 ms | 27976 KB |
02-11.txt | AC | 113 ms | 30792 KB |
02-12.txt | AC | 128 ms | 27976 KB |
02-13.txt | AC | 125 ms | 33992 KB |
sample-01.txt | AC | 28 ms | 18016 KB |
sample-02.txt | AC | 28 ms | 18016 KB |