This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MxP = 2000020;
int nxt[MxP];
bool visited[MxP];
signed main(int argc, char *argv[]) {
cin.tie(nullptr)->ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for(int i=0; i<MxP - 1; ++i) {
nxt[i] = i + 1;
}
nxt[MxP - 1] = 1;
for(int i=1, l, r; i<=n; ++i) {
cin >> l >> r;
nxt[l - 1] = r;
nxt[r - 1] = l;
}
vector<int> v;
for(int i=0; i<MxP; ++i) {
if(visited[i]) {
continue;
}
int cur = i, cnt_warp = 0;
while(!visited[cur]) {
visited[cur] = true;
if(nxt[cur] != cur + 1) {
cnt_warp++;
}
cur = nxt[cur];
}
v.emplace_back(cnt_warp);
}
int answer = v[0] + (m + 1) / 2 + (m / 2) * 3;
sort(v.begin(), v.end(), greater<int> ());
for(int i=0; i<m && i<(int) v.size(); ++i) {
answer += 2 + v[i];
}
cout << answer << "\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... |