結果
問題 | No.556 仁義なきサルたち |
ユーザー | 👑 testestest |
提出日時 | 2017-11-06 08:13:54 |
言語 | C (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 542 bytes |
コンパイル時間 | 249 ms |
コンパイル使用メモリ | 30,336 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-24 03:06:04 |
合計ジャッジ時間 | 1,219 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 0 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 3 ms
5,248 KB |
testcase_20 | AC | 3 ms
5,248 KB |
testcase_21 | AC | 3 ms
5,248 KB |
コンパイルメッセージ
main.c:6:1: warning: data definition has no type or storage class 6 | n,m,a,b; | ^ main.c:6:1: warning: type defaults to 'int' in declaration of 'n' [-Wimplicit-int] main.c:6:3: warning: type defaults to 'int' in declaration of 'm' [-Wimplicit-int] 6 | n,m,a,b; | ^ main.c:6:5: warning: type defaults to 'int' in declaration of 'a' [-Wimplicit-int] 6 | n,m,a,b; | ^ main.c:6:7: warning: type defaults to 'int' in declaration of 'b' [-Wimplicit-int] 6 | n,m,a,b; | ^ main.c:7:1: warning: return type defaults to 'int' [-Wimplicit-int] 7 | main(){ | ^~~~ main.c: In function 'main': main.c:8:9: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration] 8 | scanf("%d%d",&n,&m); | ^~~~~ main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf' +++ |+#include <stdio.h> 1 | int uniroot[10010],unicnt[10010]; main.c:8:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch] 8 | scanf("%d%d",&n,&m); | ^~~~~ main.c:8:9: note: include '<stdio.h>' or provide a declaration of 'scanf' main.c:17:30: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 17 | for(int i=1;i<=n;i++)printf("%d\n",root(i)); | ^~~~~~ main.c:17:30: note: include '<stdio.h>' or provide a declaration of 'printf' main.c:17:30: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch] main.c:17:30: note: include '<stdio.h>' or provide a declaration of 'printf'
ソースコード
int uniroot[10010],unicnt[10010]; void ufinit(int n){for(int i=0;i<n;i++){uniroot[i]=i;unicnt[i]=1;}} int root(int x){return uniroot[x]!=x?uniroot[x]=root(uniroot[x]):x;} void uni(int x,int y){if((x=root(x))==(y=root(y)))return;uniroot[x]=y;unicnt[x]+=unicnt[y];unicnt[y]=unicnt[x];} n,m,a,b; main(){ scanf("%d%d",&n,&m); ufinit(n+1); while(m--){ scanf("%d%d",&a,&b); if(root(a)!=root(b)){ if(unicnt[a]<unicnt[b]||unicnt[a]==unicnt[b]&&root(a)>root(b))a^=b^=a^=b; uni(b,a); } } for(int i=1;i<=n;i++)printf("%d\n",root(i)); }