이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
int nxt[1 + N + 1];
bool used[1 + N + 1];
typedef long long ll;
int main(){
ios::sync_with_stdio (false);
cin.tie (0); cout.tie (0);
for (int i = 1; i <= N; i++)
nxt[i] = i + 1;
used[N + 1] = true;
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int x, y;
cin >> x >> y;
nxt[x] = y + 1;
nxt[y] = x + 1;
}
int ans = -1;
priority_queue <int> pq;
for (int i = 1; i <= N; i++) {
if (used[i] == false) {
int cur = i, cnt = 0;
while (used[cur] == false) {
used[cur] = true;
if (nxt[cur] != cur + 1)
cnt++;
cur = nxt[cur];
}
if (ans == -1)
ans = cnt;
else
pq.push (cnt);
}
}
while (pq.size () && m){
ans += pq.top () + 2;
pq.pop ();
m--;
}
ans += (m + 1) / 2;
ans += (m / 2) * 3;
cout << ans << "\n";
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... |