結果

問題 No.556 仁義なきサルたち
ユーザー Bantako
提出日時 2017-08-14 01:27:45
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 373 ms / 2,000 ms
コード長 1,020 bytes
コンパイル時間 1,594 ms
コンパイル使用メモリ 166,288 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 09:24:44
合計ジャッジ時間 3,354 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
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