# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
217546 | mhy908 | Teleporters (IOI08_teleporters) | C++14 | 493 ms | 30356 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 pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortvec(x) sort(all(x))
#define compress(x) x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const int st=1, fin=4000002, MAXN=2000000;
int n;
LL k, ans;
bool ch[2000010], ch2[2000010];
int link[4000010];
LL dfs(int num, int finnum){
//printf("! %d %d\n", num, finnum);
if(num%2==0)ch2[num/2]=true;
if(num==finnum)return 0;
return 1+dfs(link[num], finnum);
}
vector<LL> vc;
int main(){
scanf("%d %lld", &n, &k);
for(int i=1; i<=n; i++){
int a, b;
scanf("%d %d", &a, &b);
link[2*a]=2*b+1;
link[2*b]=2*a+1;
ch[a]=ch[b]=true;
}
ch[MAXN+1]=true;
int pv=0;
for(int i=1; i<=MAXN+1; i++){
if(ch[i]){
link[2*pv+1]=2*i;
pv=i;
}
}
ans=dfs(st, fin)/2;
for(int i=1; i<=MAXN; i++){
if(!ch[i]||ch2[i])continue;
vc.pb((dfs(link[2*i], 2*i)+1)/2);
}
sort(all(vc), greater<LL>());
for(auto i:vc){
ans+=i+2;
k--;
if(!k)break;
}
ans+=(k+1)/2+k/2*3;
printf("%lld", ans);
}
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... |