結果

問題 No.556 仁義なきサルたち
ユーザー BantakoBantako
提出日時 2017-08-14 01:27:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 394 ms / 2,000 ms
コード長 1,020 bytes
コンパイル時間 1,858 ms
コンパイル使用メモリ 163,092 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 10:34:52
合計ジャッジ時間 3,718 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 5 ms
6,944 KB
testcase_13 AC 11 ms
6,940 KB
testcase_14 AC 25 ms
6,944 KB
testcase_15 AC 42 ms
6,944 KB
testcase_16 AC 45 ms
6,940 KB
testcase_17 AC 75 ms
6,940 KB
testcase_18 AC 180 ms
6,944 KB
testcase_19 AC 394 ms
6,940 KB
testcase_20 AC 135 ms
6,940 KB
testcase_21 AC 134 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
int boss[10000];
int cnt[10000];
int N,M;
//lの値をwに
void update(int l,int w,ll s){
    for(int i = 0;i < N;i++){
        if(boss[i] == w || boss[i] == l){
            boss[i] = w;
            cnt[i] = s;
        }
    }
}
main(){
    cin >> N >> M;
    for(int i = 0;i < N;i++){boss[i] = i+1;cnt[i] = 1;}
    for(int i = 0;i < M;i++){
        int a,b;
        cin >> a >> b;
        int win,lose;
        if(boss[a-1] == boss[b-1])continue;
        if(cnt[a-1] == cnt[b-1]){
            win = min(boss[a-1],boss[b-1]);
            lose = max(boss[a-1],boss[b-1]);
        }else{
            if(cnt[a-1] > cnt[b-1]){
                win = boss[a-1];
                lose = boss[b-1];
            }else{
                win = boss[b-1];
                lose = boss[a-1];
            }
        }
        update(lose,win,cnt[a-1]+cnt[b-1]);
    }
    for(int i = 0;i < N;i++){
        cout << boss[i] << endl;
    }
}
0