結果

問題 No.1293 2種類の道路
ユーザー tailstails
提出日時 2020-11-24 01:14:09
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,475 bytes
コンパイル時間 1,495 ms
コンパイル使用メモリ 31,596 KB
実行使用メモリ 12,796 KB
最終ジャッジ日時 2023-10-01 00:42:40
合計ジャッジ時間 2,781 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 21 ms
12,720 KB
testcase_10 AC 21 ms
12,624 KB
testcase_11 AC 20 ms
12,796 KB
testcase_12 AC 20 ms
12,724 KB
testcase_13 AC 20 ms
12,628 KB
testcase_14 AC 16 ms
11,508 KB
testcase_15 AC 17 ms
11,480 KB
testcase_16 AC 17 ms
12,228 KB
testcase_17 AC 16 ms
12,568 KB
testcase_18 AC 14 ms
11,548 KB
testcase_19 AC 16 ms
11,472 KB
testcase_20 AC 16 ms
11,632 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:55:1: 警告: 戻り値の型をデフォルトの ‘int’ にします [-Wimplicit-int]
   55 | main(){
      | ^~~~
main.c: 関数 ‘main’ 内:
main.c:82:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   82 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c:83:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   83 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

char*mmap();
#define RD(v) int v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}

#define WTHI(v) {long _z=v,_n=0,_d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(long*)wp=_d;wp+=_n;}
#define WTLO(v) {long _z=v,_n=8,_d=0;while(_d=_d<<8|0x30|_z%10,_z/=10,--_n);*(long*)wp=_d;wp+=8;}
#define WT(v) if(v>=100000000){WTHI(v/100000000);WTLO(v);}else{WTHI(v);}


#define HASH_BITS 20
long hash[1<<HASH_BITS];
int hash_add(long x){
	int h=x&(1<<HASH_BITS)-1;
	while(1){
		if(hash[h]==0){
			hash[h]=x;
			return 1;
		}
		if(hash[h]==x){
			return 0;
		}
		h=h+1&(1<<HASH_BITS)-1;
	}
}

int ufbuf[200002];
void uf_init(){
	for(int i=0;i<200002;++i){
		ufbuf[i]=-1;
	}
}
int uf_find(int a){
	int b;
	int t=a;
	while(b=ufbuf[t],b>=0) t=b;
	while(b=ufbuf[a],b>=0) ufbuf[a]=t,a=b;
	return t;
}
void uf_unite(int a,int b){
	a=uf_find(a);
	b=uf_find(b);
	if(a!=b){
		if(ufbuf[a]<ufbuf[b]){
			ufbuf[a]+=ufbuf[b];
			ufbuf[b]=a;
		}else{
			ufbuf[b]+=ufbuf[a];
			ufbuf[a]=b;
		}
	}
}

main(){
	uf_init();
	char*rp=mmap(0l,7l*400004,1,2,0,0ll);
	RD(n);
	RD(v);
	RD(w);
	for(int i=0;i<v;++i){
		RD(a);
		RD(b);
		uf_unite(a,b);
	}
	for(int i=0;i<w;++i){
		RD(a);
		RD(b);
		uf_unite(a+n,b+n);
	}
	long z=-n;
	for(int i=1;i<=n;++i){
		int a=uf_find(i);
		int b=uf_find(i+n);
		long x=a+(1l<<32|307)*(b-n);
		if(hash_add(x)){
			z+=(long)ufbuf[a]*(long)ufbuf[b];
		}
	}
	char wbuf[16],*wp=wbuf;
	WT(z);
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0