提出 #64289865
ソースコード 拡げる
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pii pair<int, int>
#define endl '\n'
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
void dbg_out() { cerr << endl; }
template<typename H, typename... T>
void dbg_out(H h, T... t) {
cerr << ' ' << h;
dbg_out(t...);
}
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }
inline int read() {
int n=0,f=1,ch=getchar();
while(ch<'0'||ch>'9') {
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9') {
n=n*10+ch-'0';
ch=getchar();
}
return n*f;
}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int fa[N];
int find(int x) {
if (fa[x] != x) {
fa[x] = find(fa[x]);
}
return fa[x];
}
void merge(int x, int y) {
x = find(x);
y = find(y);
if (x != y) {
fa[x] = y;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m; cin>>n>>m;
int ans = 0;
for(int i = 1;i <= n;i++) fa[i] = i;
for(int i = 0;i < m;i++)
{
int x,y; cin>>x>>y;
x = find(x);
y = find(y);
if(x == y) ans++;
else merge(x,y);
}
cout << ans << endl;
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Make it Forest |
| ユーザ | yunjie |
| 言語 | C++ 17 (gcc 12.2) |
| 得点 | 350 |
| コード長 | 1792 Byte |
| 結果 | AC |
| 実行時間 | 25 ms |
| メモリ | 4392 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 350 / 350 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 02_min_00.txt, 02_min_01.txt, 03_max_00.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3540 KiB |
| 00_sample_01.txt | AC | 1 ms | 3476 KiB |
| 00_sample_02.txt | AC | 1 ms | 3484 KiB |
| 01_random_00.txt | AC | 24 ms | 3968 KiB |
| 01_random_01.txt | AC | 19 ms | 4248 KiB |
| 01_random_02.txt | AC | 25 ms | 4220 KiB |
| 01_random_03.txt | AC | 25 ms | 4244 KiB |
| 01_random_04.txt | AC | 22 ms | 3944 KiB |
| 01_random_05.txt | AC | 16 ms | 4392 KiB |
| 01_random_06.txt | AC | 24 ms | 3852 KiB |
| 01_random_07.txt | AC | 25 ms | 4320 KiB |
| 01_random_08.txt | AC | 18 ms | 3916 KiB |
| 01_random_09.txt | AC | 19 ms | 4260 KiB |
| 01_random_10.txt | AC | 25 ms | 3916 KiB |
| 01_random_11.txt | AC | 25 ms | 4256 KiB |
| 02_min_00.txt | AC | 1 ms | 3476 KiB |
| 02_min_01.txt | AC | 1 ms | 4236 KiB |
| 03_max_00.txt | AC | 14 ms | 3480 KiB |