結果
| 問題 |
No.556 仁義なきサルたち
|
| ユーザー |
👑 testestest
|
| 提出日時 | 2017-11-06 08:15:52 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 580 bytes |
| コンパイル時間 | 541 ms |
| コンパイル使用メモリ | 30,592 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-24 03:06:06 |
| 合計ジャッジ時間 | 885 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
コンパイルメッセージ
main.c:7:1: warning: data definition has no type or storage class
7 | n,m,a,b;
| ^
main.c:7:1: warning: type defaults to 'int' in declaration of 'n' [-Wimplicit-int]
main.c:7:3: warning: type defaults to 'int' in declaration of 'm' [-Wimplicit-int]
7 | n,m,a,b;
| ^
main.c:7:5: warning: type defaults to 'int' in declaration of 'a' [-Wimplicit-int]
7 | n,m,a,b;
| ^
main.c:7:7: warning: type defaults to 'int' in declaration of 'b' [-Wimplicit-int]
7 | n,m,a,b;
| ^
main.c:8:1: warning: return type defaults to 'int' [-Wimplicit-int]
8 | main(){
| ^~~~
main.c: In function 'main':
main.c:9:9: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
9 | scanf("%d%d",&n,&m);
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | #define LIMIT 10000
main.c:9:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
9 | scanf("%d%d",&n,&m);
| ^~~~~
main.c:9:9: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:18:30: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
18 | for(int i=1;i<=n;i++)printf("%d\n",root(i));
| ^~~~~~
main.c:18:30: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:18:30: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:18:30: note: include '<stdio.h>' or provide a declaration of 'printf'
ソースコード
#define LIMIT 10000
int uniroot[LIMIT+10],unicnt[LIMIT+10];
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;}
int ucnt(int x){return unicnt[root(x)];}
void uni(int x,int y){if((x=root(x))==(y=root(y)))return;uniroot[x]=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(ucnt(a)<ucnt(b)||ucnt(a)==ucnt(b)&&root(a)>root(b))a^=b^=a^=b;
uni(b,a);
}
}
for(int i=1;i<=n;i++)printf("%d\n",root(i));
}
testestest