提出 #4573097
ソースコード 拡げる
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;
// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;
// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;
// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
struct UnionFind {
vector< int > par;
UnionFind(int n = 1) {
init(n);
}
void init(int n = 1) {
par.resize(n);
for(int i = 0; i < n; i++)
par[i] = -1;
}
int root(int n) {
if (par[n] < 0) return n;
return par[n] = root(par[n]);
}
bool merge(int x, int y) {
x = root(x); y = root(y);
if (x == y) return false;
if (par[x] > par[y]) swap(x, y);
par[x] += par[y];
par[y] = x;
return true;
}
bool issame(int x, int y) {
return root(x) == root(y);
}
int getSize(int x){
return -(par[root(x)]);
}
};
signed main() {
INIT;
VAR(int,n,k,l);
UnionFind uf_train(2*n+1);
REP(i,k){
VAR(int,p,q);
uf_train.merge(p-1,q-1);
}
UnionFind uf_road(2*n+1);
REP(i,l){
VAR(int,r,s);
uf_road.merge(r-1,s-1);
}
map<pair<int,int>,int> cnt;
REP(i,n){
++cnt[make_pair(uf_train.root(i),uf_road.root(i))];
}
int isFirst = true;
REP(i,n){
if(isFirst) isFirst = false;
else SP;
OUT(cnt[make_pair(uf_train.root(i),uf_road.root(i))]);
}
BR;
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
D - 連結 |
| ユーザ |
task4233 |
| 言語 |
C++14 (GCC 5.4.1) |
| 得点 |
400 |
| コード長 |
2296 Byte |
| 結果 |
AC |
| 実行時間 |
153 ms |
| メモリ |
18176 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
400 / 400 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
subtask0_0.txt, subtask0_1.txt, subtask0_2.txt |
| All |
subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask1_0.txt, subtask1_1.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_2.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| subtask0_0.txt |
AC |
1 ms |
256 KiB |
| subtask0_1.txt |
AC |
1 ms |
256 KiB |
| subtask0_2.txt |
AC |
1 ms |
256 KiB |
| subtask1_0.txt |
AC |
27 ms |
384 KiB |
| subtask1_1.txt |
AC |
153 ms |
18176 KiB |
| subtask1_10.txt |
AC |
28 ms |
384 KiB |
| subtask1_11.txt |
AC |
135 ms |
16128 KiB |
| subtask1_12.txt |
AC |
83 ms |
15744 KiB |
| subtask1_13.txt |
AC |
92 ms |
17152 KiB |
| subtask1_14.txt |
AC |
88 ms |
12416 KiB |
| subtask1_2.txt |
AC |
70 ms |
12160 KiB |
| subtask1_3.txt |
AC |
91 ms |
17152 KiB |
| subtask1_4.txt |
AC |
89 ms |
13568 KiB |
| subtask1_5.txt |
AC |
29 ms |
384 KiB |
| subtask1_6.txt |
AC |
131 ms |
15104 KiB |
| subtask1_7.txt |
AC |
92 ms |
17280 KiB |
| subtask1_8.txt |
AC |
95 ms |
17408 KiB |
| subtask1_9.txt |
AC |
79 ms |
9472 KiB |