結果
| 問題 |
No.330 Eigenvalue Decomposition
|
| コンテスト | |
| ユーザー |
kuuso1
|
| 提出日時 | 2015-12-23 01:20:59 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 275 ms / 5,000 ms |
| コード長 | 1,946 bytes |
| コンパイル時間 | 1,093 ms |
| コンパイル使用メモリ | 107,264 KB |
| 実行使用メモリ | 26,624 KB |
| 最終ジャッジ日時 | 2024-09-18 19:22:54 |
| 合計ジャッジ時間 | 5,030 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 31 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}
class Sol{
public void Solve(){
var UF=new UnionFind(N);
for(int i=0;i<M;i++){
var d=ria();
UF.Union(d[0]-1,d[1]-1);
}
Console.WriteLine(UF.Compo);
}
int N,M;
public Sol(){
var d=ria();
N=d[0];M=d[1];
}
static String rs(){return Console.ReadLine();}
static int ri(){return int.Parse(Console.ReadLine());}
static long rl(){return long.Parse(Console.ReadLine());}
static double rd(){return double.Parse(Console.ReadLine());}
static String[] rsa(){return Console.ReadLine().Split(' ');}
static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
class UnionFind{
int[] parent;
int[] mem;
int compo;
int N;
public UnionFind(int n_){
Initialize(n_);
}
public void Initialize(int n_){
N=n_;
parent=new int[N];
mem=new int[N];
for(int i=0;i<N;i++){
parent[i]=i;
mem[i]=1;
}
compo=N;
}
public int Parent(int a){
if(parent[a]==a)return a;
return parent[a]=Parent(parent[a]);
}
public bool areSameGp(int a,int b){
return Parent(a)==Parent(b);
}
public void Union(int a,int b){
a=Parent(a);b=Parent(b);//Parent()を呼ぶことでa以上のノードは全てparentがrootになる
if(a==b)return;
parent[a]=b;
mem[b]+=mem[a];
compo-=1;
}
public bool isRoot(int x){
return x==parent[x];
}
public int MemCnt(int x){
return mem[x];
}
public void Dump(){
for(int i=0;i<parent.Length;i++){
Console.Write(i==0?"{0}":" {0}",parent[i]);
}
Console.WriteLine("");
}
public int Compo{
get{
return compo;
}
}
}
kuuso1