結果
問題 | No.556 仁義なきサルたち |
ユーザー | pekempey |
提出日時 | 2017-08-11 23:04:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 283 ms / 2,000 ms |
コード長 | 773 bytes |
コンパイル時間 | 660 ms |
コンパイル使用メモリ | 75,400 KB |
最終ジャッジ日時 | 2025-01-05 02:14:19 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <string> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> boss(n); for (int i = 0; i < n; i++) { boss[i] = i; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; a = boss[a]; b = boss[b]; int sa = 0; int sb = 0; for (int j = 0; j < n; j++) { if (boss[j] == a) sa++; if (boss[j] == b) sb++; } if (sa > sb || (sa == sb && a < b)) { for (int j = 0; j < n; j++) { if (boss[j] == b) boss[j] = a; } } else { for (int j = 0; j < n; j++) { if (boss[j] == a) boss[j] = b; } } } for (int i = 0; i < n; i++) { cout << boss[i] + 1 << endl; } }