Submission #1061224
Source Code Expand
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
#include <math.h>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n ; i++)
#define pb push_back
static const int INF = 1000000;
static const int MAX = 200000;
typedef pair<int, int> P;
typedef pair<P, int> PP;
vector<int> G[MAX];
vector<int> G_rail[MAX];
//1はじまりあ
bool grouped[MAX];
bool grouped_rail[MAX];
int groupingNum[MAX];
class DisJointSet {
public:
vector<int> rank,p;
DisJointSet(){}
DisJointSet(int size){
rank.resize(size,0);
p.resize(size,0);
for(int i = 0; i < size; i++) makeSet(i);
}
void makeSet(int x){
p[x] = x;
rank[x] = 0;
}
bool same(int x, int y){
return findSet(x) == findSet(y);
}
void unite(int x, int y){
link(findSet(x), findSet(y));
}
void link(int x, int y){
if( rank[x] > rank[y] ){
p[y] = x;
}else {
p[x] = y;
if( rank[x] == rank[y]){
rank[y] ++;
}
}
}
int findSet(int x){
if ( x != p[x] ){
p[x] = findSet(p[x]);
}
return p[x];
}
};
int main(void){
int N,K,L; cin >> N >> K >> L;
DisJointSet road(N+1);
DisJointSet rail(N+1);
int a,b;
rep(i,K){
cin >> a >> b;
road.unite(a,b);
}
rep(i,L){
cin >> a >> b;
rail.unite(a,b);
}
map<P,int> mp;
int c,d;
rep(i,N){
c = road.findSet(i+1);
d = rail.findSet(i+1);
mp[P(c,d)] += 1;
}
rep(i,N){
c = road.findSet(i+1);
d = rail.findSet(i+1);
cout << mp[P(c,d)] << " ";
}
cout << endl;
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - Connectivity |
| User |
imitation0813 |
| Language |
C++14 (GCC 5.4.1) |
| Score |
400 |
| Code Size |
1758 Byte |
| Status |
AC |
| Exec Time |
218 ms |
| Memory |
24448 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| 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 |
| Case Name |
Status |
Exec Time |
Memory |
| subtask0_0.txt |
AC |
12 ms |
9600 KiB |
| subtask0_1.txt |
AC |
12 ms |
9600 KiB |
| subtask0_2.txt |
AC |
12 ms |
9600 KiB |
| subtask1_0.txt |
AC |
94 ms |
9600 KiB |
| subtask1_1.txt |
AC |
218 ms |
24448 KiB |
| subtask1_10.txt |
AC |
99 ms |
9728 KiB |
| subtask1_11.txt |
AC |
209 ms |
22784 KiB |
| subtask1_12.txt |
AC |
167 ms |
22272 KiB |
| subtask1_13.txt |
AC |
176 ms |
23552 KiB |
| subtask1_14.txt |
AC |
185 ms |
19328 KiB |
| subtask1_2.txt |
AC |
146 ms |
19200 KiB |
| subtask1_3.txt |
AC |
183 ms |
23552 KiB |
| subtask1_4.txt |
AC |
188 ms |
20352 KiB |
| subtask1_5.txt |
AC |
100 ms |
9728 KiB |
| subtask1_6.txt |
AC |
200 ms |
22016 KiB |
| subtask1_7.txt |
AC |
168 ms |
23552 KiB |
| subtask1_8.txt |
AC |
188 ms |
23680 KiB |
| subtask1_9.txt |
AC |
172 ms |
16768 KiB |