# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1046533 | Andrey | Marshmallow Molecules (CCO19_day2problem2) | C++14 | 31 ms | 18888 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
vector<int> dsu(100001);
vector<int> haha[100001];
vector<int> bruh[100001];
set<int> idk[100001];
int calc(int a) {
int c = a;
while(dsu[c] != c) {
c = dsu[c];
}
int e = a;
while(dsu[e] != e) {
int d = dsu[e];
dsu[e] = c;
e = d;
}
return c;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m,a,b;
cin >> n >> m;
for(int i = 1; i <= n; i++) {
dsu[i] = i;
}
long long ans = 0;
for(int i = 0; i < m; i++) {
cin >> a >> b;
haha[a].push_back(b);
bruh[b].push_back(a);
}
for(int i = 1; i <= n; i++) {
vector<int> wut(0);
int big = -1,p = -1;
for(int v: bruh[i]) {
int x = calc(v);
wut.push_back(x);
if(idk[x].size() > big) {
big = idk[x].size();
p = x;
}
}
if(p != -1) {
swap(idk[i],idk[p]);
sort(wut.begin(),wut.end());
for(int j = 0; j < wut.size(); j++) {
if(j == 0 || wut[j] != wut[j-1]) {
int c = wut[j];
if(c == p) {
continue;
}
dsu[c] = i;
while(!idk[c].empty()) {
int x = *idk[c].lower_bound(-INT_MAX);
idk[i].insert(x);
idk[c].erase(x);
}
}
}
}
for(int v: haha[i]) {
idk[i].insert(v);
}
idk[i].erase(i);
ans+=idk[i].size();
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |