結果

問題 No.2316 Freight Train
ユーザー tailstails
提出日時 2023-05-26 23:15:17
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 27,496 KB
実行使用メモリ 6,856 KB
最終ジャッジ日時 2023-08-26 13:41:20
合計ジャッジ時間 3,472 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 16 ms
6,660 KB
testcase_04 AC 8 ms
4,516 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 8 ms
5,408 KB
testcase_08 AC 12 ms
5,100 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 9 ms
5,496 KB
testcase_11 AC 12 ms
5,560 KB
testcase_12 AC 14 ms
5,944 KB
testcase_13 AC 17 ms
6,776 KB
testcase_14 AC 17 ms
6,728 KB
testcase_15 AC 16 ms
6,728 KB
testcase_16 AC 16 ms
6,736 KB
testcase_17 AC 17 ms
6,728 KB
testcase_18 AC 16 ms
6,788 KB
testcase_19 AC 16 ms
6,724 KB
testcase_20 AC 16 ms
6,856 KB
testcase_21 AC 16 ms
6,824 KB
testcase_22 AC 17 ms
6,808 KB
testcase_23 AC 6 ms
5,968 KB
testcase_24 AC 9 ms
6,836 KB
testcase_25 AC 6 ms
6,156 KB
testcase_26 AC 4 ms
6,132 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:57:10: warning: multi-character character constant [-Wmultichar]
    *wp++='\nseY';
          ^~~~~~~
main.c:59:10: warning: multi-character character constant [-Wmultichar]
    *wp++='\n oN';
          ^~~~~~~
main.c:62:2: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
  write(1,wbuf,(wp-wbuf)*sizeof*wbuf);
  ^~~~~
main.c:63:2: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
  _exit(0);
  ^~~~~
main.c:63:2: warning: incompatible implicit declaration of built-in function ‘_exit’

ソースコード

diff #

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

#define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);})
#define rd_skip() while(*rp++>=48)
#define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define rep(v,e) for(typeof(e) v=0;v<e;++v)

#define UFSIZE 200002
int ufbuf[UFSIZE];
void uf_init(){
	for(int i=0;i<UFSIZE;++i){
		ufbuf[i]=-1;
	}
}
int uf_root(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_root(a);
	b=uf_root(b);
	if(a!=b){
		if(ufbuf[a]<ufbuf[b]){
			ufbuf[a]+=ufbuf[b];
			ufbuf[b]=a;
		}else{
			ufbuf[b]+=ufbuf[a];
			ufbuf[a]=b;
		}
	}
}

unsigned wbuf[1<<20];

int main(){
	uf_init();
	rd_init();
	int n=rd();
	rd_skip();
	rep(i,n){
		if(*rp=='-'){
			rp+=3;
		}else{
			int p=rd();
			uf_unite(i+1,p);
		}
	}
	unsigned*wp=wbuf;
	while(*rp){
		int a=rd();
		int b=rd();
		if(uf_root(a)==uf_root(b)){
			*wp++='\nseY';
		}else{
			*wp++='\n oN';
		}
	}
	write(1,wbuf,(wp-wbuf)*sizeof*wbuf);
	_exit(0);
}
0