結果

問題 No.1639 最小通信路
ユーザー tailstails
提出日時 2021-08-10 18:54:40
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 872 bytes
コンパイル時間 1,110 ms
コンパイル使用メモリ 30,108 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 04:05:28
合計ジャッジ時間 2,672 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 1 ms
4,348 KB
testcase_40 AC 1 ms
4,348 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 1 ms
4,348 KB
testcase_43 AC 1 ms
4,348 KB
testcase_44 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:39:1: warning: return type defaults to 'int' [-Wimplicit-int]
   39 | main(){
      | ^~~~
main.c: In function 'main':
main.c:49:20: warning: implicit declaration of function 'strchr' [-Wimplicit-function-declaration]
   49 |                 rp=strchr(rp,'\n')+1;
      |                    ^~~~~~
main.c:1:1: note: include '<string.h>' or provide a declaration of 'strchr'
  +++ |+#include <string.h>
    1 | #pragma GCC optimize("Ofast")
main.c:49:20: warning: incompatible implicit declaration of built-in function 'strchr' [-Wbuiltin-declaration-mismatch]
   49 |                 rp=strchr(rp,'\n')+1;
      |                    ^~~~~~
main.c:49:20: note: include '<string.h>' or provide a declaration of 'strchr'
main.c:55:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
   55 |         write(1,resp,resn);
      |         ^~~~~
main.c:56:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
   56 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

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

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

#define UFSIZE 101
long ufbuf[UFSIZE];
void uf_init(){
	for(long i=0;i<UFSIZE;++i){
		ufbuf[i]=-1;
	}
}
long uf_root(long a){
	long b;
	long t=a;
	while(b=ufbuf[t],b>=0) t=b;
	while(b=ufbuf[a],b>=0) ufbuf[a]=t,a=b;
	return t;
}
long uf_unite(long a,long 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;
		}
		return 1;
	}else{
		return 0;
	}
}

main(){
	uf_init();
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	rd_skip();
	char*resp;
	long resn;
	while(*rp){
		rd(a);
		rd(b);
		char*c=rp;
		rp=strchr(rp,'\n')+1;
		if(uf_unite(a,b)){
			resp=c;
			resn=rp-c;
		}
	}
	write(1,resp,resn);
	_exit(0);
}
0