結果

問題 No.556 仁義なきサルたち
ユーザー kotatsugamekotatsugame
提出日時 2017-08-11 23:17:59
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 316 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 30,080 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 21:51:53
合計ジャッジ時間 942 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,248 KB
testcase_04 AC 1 ms
5,248 KB
testcase_05 AC 1 ms
5,248 KB
testcase_06 AC 1 ms
5,248 KB
testcase_07 AC 1 ms
5,248 KB
testcase_08 AC 1 ms
5,248 KB
testcase_09 AC 1 ms
5,248 KB
testcase_10 AC 1 ms
5,248 KB
testcase_11 AC 1 ms
5,248 KB
testcase_12 AC 2 ms
5,248 KB
testcase_13 AC 1 ms
5,248 KB
testcase_14 AC 2 ms
5,248 KB
testcase_15 AC 2 ms
5,248 KB
testcase_16 AC 3 ms
5,248 KB
testcase_17 AC 3 ms
5,248 KB
testcase_18 AC 4 ms
5,248 KB
testcase_19 AC 3 ms
5,248 KB
testcase_20 AC 3 ms
5,248 KB
testcase_21 AC 4 ms
5,248 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:1:3: warning: multi-character character constant [-Wmultichar]
    1 | p['~~'];c['~~'];i;a,b;
      |   ^~~~
main.c:1:1: warning: data definition has no type or storage class
    1 | p['~~'];c['~~'];i;a,b;
      | ^
main.c:1:1: warning: type defaults to 'int' in declaration of 'p' [-Wimplicit-int]
main.c:1:11: warning: multi-character character constant [-Wmultichar]
    1 | p['~~'];c['~~'];i;a,b;
      |           ^~~~
main.c:1:9: warning: data definition has no type or storage class
    1 | p['~~'];c['~~'];i;a,b;
      |         ^
main.c:1:9: warning: type defaults to 'int' in declaration of 'c' [-Wimplicit-int]
main.c:1:17: warning: data definition has no type or storage class
    1 | p['~~'];c['~~'];i;a,b;
      |                 ^
main.c:1:17: warning: type defaults to 'int' in declaration of 'i' [-Wimplicit-int]
main.c:1:19: warning: data definition has no type or storage class
    1 | p['~~'];c['~~'];i;a,b;
      |                   ^
main.c:1:19: warning: type defaults to 'int' in declaration of 'a' [-Wimplicit-int]
main.c:1:21: warning: type defaults to 'int' in declaration of 'b' [-Wimplicit-int]
    1 | p['~~'];c['~~'];i;a,b;
      |                     ^
main.c:2:1: warning: return type defaults to 'int' [-Wimplicit-int]
    2 | f(a){return p[a]-a?p[a]=f(p[a]):a;}
      | ^
main.c: In function 'f':
main.c:2:1: warning: type of 'a' defaults to 'int' [-Wimplicit-int]
main.c: At top level:
main.c:3:1: warning: return type defaults to 'int' [-Wimplicit-int]
    3 | main(n){
      | ^~~~
main.c: In function 'main':
main.c:3:1: warning: type of 'n' defaults to 'int' [-Wimplicit-int]
main.c:4:13: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
    4 |         for(scanf("%d%*d",&n);i++<n;c[i]=1)p[i]=i;
      |             ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | p['~~'];c['~~'];i;a,b;
main.c:4:13: warning: incompatible implicit declaration of buil

ソースコード

diff #

p['~~'];c['~~'];i;a,b;
f(a){return p[a]-a?p[a]=f(p[a]):a;}
main(n){
	for(scanf("%d%*d",&n);i++<n;c[i]=1)p[i]=i;
	for(;~scanf("%d%d",&a,&b);)
	{
		a=f(a),b=f(b);
		a-b&&(c[a]>c[b]?p[b]=a,c[a]+=c[b]:c[a]<c[b]?p[a]=b,c[b]+=c[a]:p[a]<p[b]?p[b]=a,c[a]+=c[b]:(p[a]=b,c[b]+=c[a]));
	}
	for(i=0;i++<n;)printf("%d\n",f(i));
}
0