# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1029586 | kunzaZa183 | Teleporters (IOI08_teleporters) | C++17 | 444 ms | 40628 KiB |
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;
int tp[2000001];
bool vb[2000005];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, m;
cin >> n >> m;
vector<int> vi;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
vi.push_back(a), vi.push_back(b);
tp[a] = b, tp[b] = a;
}
vi.push_back(0);
sort(vi.begin(), vi.end());
// for (auto a : vpii) cout << a.first << " " << a.second << "\n";
vector<int> cyc;
int special;
for (int i = 0; i < vi.size(); i++)
if (!vb[i]) {
// cout << "I = " << i << '\n';
int cy = 0;
int cur = i;
while (1) {
if (cur == vi.size()) {
special = cy - 1;
break;
}
// cout << cur << "\n";
if (vb[cur]) {
cyc.push_back(cy);
break;
}
vb[cur] = 1;
cy++;
cur = lower_bound(vi.begin(), vi.end(), tp[vi[cur]]) - vi.begin() + 1;
};
}
// for (auto a : cyc) cout << a << ' ';
// cout << "\n";
sort(cyc.begin(), cyc.end(), greater<int>());
if (m >= cyc.size()) {
int x = (m - cyc.size());
int val = x / 2 * 4 + x % 2;
cout << special + accumulate(cyc.begin(), cyc.end(), 0) + cyc.size() * 2 +
val
<< "\n";
} else
cout << special + accumulate(cyc.begin(), cyc.begin() + m, 0) + 2 * m
<< "\n";
}
Compilation message (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... |
# | 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... |