結果
| 問題 |
No.556 仁義なきサルたち
|
| ユーザー |
1119_2916
|
| 提出日時 | 2017-08-11 23:12:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 17 ms / 2,000 ms |
| コード長 | 1,791 bytes |
| コンパイル時間 | 1,436 ms |
| コンパイル使用メモリ | 162,672 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-12 21:46:27 |
| 合計ジャッジ時間 | 2,285 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | #define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:55:5: note: in expansion of macro ‘int2’
55 | int2(n, m);
| ^~~~
main.cpp:23:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | #define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:58:9: note: in expansion of macro ‘int2’
58 | int2(a, b);
| ^~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination topcoder lcm
struct UnionFind {
vector<int> parent;
int size;
UnionFind(int n) :parent(n, -1), size(n) {}
bool unite(int x, int y) {
x = root(x); y = root(y);
if (x == y)return false;
if (sizeOf(x) < sizeOf(y))swap(x, y);
if (sizeOf(x) == sizeOf(y) && x > y) swap(x, y);
parent[x] += parent[y]; parent[y] = x; size--;
return true;
}
bool same(int x, int y) { return root(x) == root(y); }
int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
int sizeOf(int x) { return -parent[root(x)]; }
};
signed main()
{
int2(n, m);
UnionFind funami_yui(n);
rep(i, m) {
int2(a, b);
a--; b--;
funami_yui.unite(a, b);
}
rep(i, n) {
std::cout << funami_yui.root(i)+1 << std::endl;
}
return 0;
}
1119_2916