# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
80151 | Sherazin | Teleporters (IOI08_teleporters) | C++14 | 1097 ms | 66560 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>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 2e6+5;
int n, m;
int chk[N], sz[N], mp[N], comp;
vector<int> pos;
int get(int x) { return lower_bound(pos.begin(), pos.end(), x) - pos.begin(); }
int main() {
scanf("%d %d", &n, &m);
for(int i = 1, a, b; i <= n; i++) {
scanf("%d %d", &a, &b);
pos.emplace_back(a), pos.emplace_back(b);
mp[a] = b, mp[b] = a;
}
pos.emplace_back(N-1);
sort(pos.begin(), pos.end());
for(int i = 0; i < 2*n; i++) if(!chk[i]) {
chk[i] = ++comp;
queue<int> Q;
Q.emplace(i);
while(!Q.empty()) {
int u = Q.front();
Q.pop();
++sz[comp];
int v = get(mp[pos[u]]) + 1;
if(chk[v] || v == 2*n) continue;
chk[v] = comp;
Q.emplace(v);
}
}
int ans = sz[1];
vector<int> V;
for(int i = 2; i <= comp; i++) V.emplace_back(sz[i]);
sort(V.begin(), V.end(), greater<int>());
for(int i = 0; i < V.size() && m; i++, m--) ans += V[i] + 2;
if(m) ans += 2*(m - (m & 1)) + (m & 1);
printf("%d\n", ans);
return 0;
}
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... |