# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
724553 | khanhdz06 | Teleporters (IOI08_teleporters) | C++17 | 358 ms | 40800 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 <iostream>
#include <vector>
#include <queue>
#define ep emplace
#define eb emplace_back
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
const ll maxn=2e6+5;
const ll mod= 1e9+7 ;
const ll base=3e18 ;
ll n, m, tel[maxn];
bool vis[maxn];
priority_queue<ll> pq;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
if (fopen("cheetos.in","r"))
{
freopen("cheetos.in","r",stdin);
freopen("cheetos.out","w",stdout);
}
for (ll i=0;i<maxn;i++)
{
tel[i]=i+1;
}
cin>> n>> m;
for (ll i=1;i<=n;i++)
{
ll l, r;
cin>> l>> r;
tel[l-1]=r;
tel[r-1]=l;
}
ll len=-1;
vis[maxn]=1;
for (ll i=0;i<maxn;i++)
{
if (!vis[i])
{
ll pos=i, ret=0;
while (!vis[pos])
{
vis[pos]=1;
if (tel[pos]!=pos+1) ret++;
pos=tel[pos];
}
if (len==-1) len=ret;
else pq.ep(ret);
}
}
while (!pq.empty()&&m)
{
len+=pq.top()+2;
pq.pop();
m--;
}
len+=(m+1)/2;
len+=(m/2)*3;
cout <<len;
}
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... |