# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
53985 | khsoo01 | Teleporters (IOI08_teleporters) | C++11 | 559 ms | 26660 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 X first
#define Y second
using namespace std;
typedef pair<int,int> pii;
const int N = 2000005;
int n, m, d[N], ans;
bool vis[N];
pii a[N];
vector<int> cs;
int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<N;i++) {
d[i] = i+1;
}
d[N-1] = 0;
for(int i=1;i<=n;i++) {
scanf("%d%d",&a[i].X,&a[i].Y);
d[a[i].X-1] = a[i].Y;
d[a[i].Y-1] = a[i].X;
}
for(int i=0;!vis[i];i=d[i]) {
if(d[i] != i+1) ans++;
vis[i] = true;
}
for(int i=0;i<N;i++) {
if(vis[i]) continue;
int C = 0;
for(int j=i;!vis[j];j=d[j]) {
if(d[j] != j+1) C++;
vis[j] = true;
}
cs.push_back(C);
}
sort(cs.begin(), cs.end());
for(int i=cs.size();i--;) {
if(!m) break;
m--;
ans += cs[i] + 2;
}
for(int i=0;i<m;i++) {
ans += i%2*2 + 1;
}
printf("%d\n", ans-1);
}
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... |