Submission #217546

#TimeUsernameProblemLanguageResultExecution timeMemory
217546mhy908Teleporters (IOI08_teleporters)C++14
100 / 100
493 ms30356 KiB
#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)

teleporters.cpp: In function 'int main()':
teleporters.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %lld", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~~~
teleporters.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...