結果

問題 No.416 旅行会社
ユーザー tailstails
提出日時 2020-11-05 21:46:43
言語 cLay
(20240104-1)
結果
AC  
実行時間 76 ms / 4,000 ms
コード長 777 bytes
コンパイル時間 2,361 ms
コンパイル使用メモリ 181,340 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-05-08 16:00:34
合計ジャッジ時間 4,430 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,704 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 25 ms
8,576 KB
testcase_11 AC 25 ms
10,496 KB
testcase_12 AC 27 ms
10,496 KB
testcase_13 AC 20 ms
10,368 KB
testcase_14 AC 73 ms
11,264 KB
testcase_15 AC 74 ms
11,596 KB
testcase_16 AC 76 ms
11,904 KB
testcase_17 AC 74 ms
11,392 KB
testcase_18 AC 73 ms
11,344 KB
testcase_19 AC 46 ms
9,600 KB
testcase_20 AC 43 ms
9,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

long ab[200000];
long cd[200000];
char xx[200000];

int en[100001];
int ei[100001];
int eb[400000];

int z[100001];

int d;
void f(int i){
	if(!z[i]){
		z[i]=d;
		for(int k=0;k<en[i];++k){
			f(eb[ei[i]+k]);
		}
	}
}

{
	int @n,@m,@q;
	rep(i,m){
		int @a,@b;
		ab[i]=(long)a<<32|b;
		++en[a];
		++en[b];
	}
	{
		int s=0;
		rep(j,1,n+1){
			ei[j]=s;
			s+=en[j];
			en[j]=0;
		}
	}
	sort(ab,ab+m);
	rep(i,q){
		int @c,@d;
		cd[i]=(long)c<<32|d;
		xx[lower_bound(ab,ab+m,cd[i])-ab]=1;
	}
	rep(i,m){
		if(!xx[i]){
			int a=ab[i]>>32;
			int b=ab[i];
			eb[ei[a]+en[a]++]=b;
			eb[ei[b]+en[b]++]=a;
		}
	}
	d=-1;
	f(1);
	rrep(i,q){
		d=i+1;
		int a=cd[i]>>32;
		int b=cd[i];
		if(z[a]) f(b);
		if(z[b]) f(a);
		eb[ei[a]+en[a]++]=b;
		eb[ei[b]+en[b]++]=a;
	}
	wtLn(((z+2))(n-1));
}
0