# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
583303 | hibiki | Teleporters (IOI08_teleporters) | C++11 | 418 ms | 23580 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;
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(),x.end()
int n,m;
pair<int,int> go[2000005];
bool pass[2000005];
int main()
{
scanf("%d %d",&n,&m);
for(int i = 0; i < 2000005; i++)
go[i] = {i + 1, 0};
for(int i = 0; i < n; i++)
{
int a,b;
scanf("%d %d",&a,&b);
go[a] = {b + 1, 1};
go[b] = {a + 1, 1};
}
int ans = 0;
priority_queue<int> pq;
pass[2000005 - 1] = true;
for(int i = 0; i < 2000005; i++)
{
if(pass[i]) continue;
int cnt = 0, nw = i;
while(!pass[nw])
{
pass[nw] = true;
cnt += go[nw].s;
nw = go[nw].f;
}
if(i == 0)
ans += cnt;
else
{
// printf("%d %d\n",i,cnt);
pq.push(cnt);
}
}
while(m > 0 && !pq.empty())
{
ans += pq.top() + 2;
pq.pop();
m--;
}
ans += (m / 2) * 4 + (m % 2);
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... |