이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 5;
const int L = 2e6 + 1;
int W[MAX_N], E[MAX_N];
pair <int, int> nxt[L + 1];
bool visited[L + 1];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, M;
cin >> N >> M;
for(int i = 0; i < L; i++) {
nxt[i] = make_pair(i + 1, 0);
}
for(int i = 1; i <= N; i++) {
cin >> W[i] >> E[i];
nxt[W[i]] = make_pair(E[i] + 1, 1);
nxt[E[i]] = make_pair(W[i] + 1, 1);
}
priority_queue <int> pq;
visited[L] = true;
int ans = 0;
for(int i = 0; i <= L; i++) {
if(visited[i] == true) {
continue;
}
int u = i, cnt = 0;
while(visited[u] == false) {
visited[u] = true;
cnt += nxt[u].second;
u = nxt[u].first;
}
if(i == 0) {
ans = cnt;
}
else {
pq.push(cnt);
}
}
while(M--) {
if(!pq.empty()) {
ans += pq.top() + 2;
pq.pop();
}
else {
pq.push(1);
ans++;
}
}
cout << ans;
return 0;
}
# | 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... |
# | 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... |
# | 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... |
# | 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... |
# | 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... |