제출 #649631

#제출 시각아이디문제언어결과실행 시간메모리
649631KoalaMuchTeleporters (IOI08_teleporters)C++14
80 / 100
1090 ms65536 KiB
#include<bits/stdc++.h> using namespace std; const int N = 2e6+5; set<int> point; int p[2*N]; int sz[2*N]; int mark[2*N]; pair<int,int> tele[N]; bool exist[2*N]; priority_queue<int> pq; int fin(int i){ if(p[i]==i) return i; return p[i] = fin(p[i]); } int main(){ /*ios_base::sync_with_stdio(false); cin.tie(0);*/ int n,m,mn=1e9; cin >> n >> m; for(int i=1;i<=2000000;i++) sz[i] = 1,p[i] = i; for(int i=0;i<n;i++){ cin >> tele[i].first >> tele[i].second; mn = min(mn,tele[i].first); exist[tele[i].first] = exist[tele[i].second] = true; point.insert(tele[i].first); point.insert(tele[i].second); } for(int i=0;i<n;i++){ auto nxt = point.upper_bound(tele[i].second); if(nxt!=point.end()&&fin(*nxt)!=fin(tele[i].first)){ sz[fin(tele[i].first)]+=sz[fin(*nxt)]; p[fin(*nxt)] = fin(tele[i].first); } nxt = point.upper_bound(tele[i].first); if(nxt!=point.end()&&fin(*nxt)!=fin(tele[i].second)){ sz[fin(tele[i].second)]+=sz[fin(*nxt)]; p[fin(*nxt)] = fin(tele[i].second); } } int ans = sz[fin(mn)]; mark[fin(mn)] = true; for(int i=1;i<=2000000;i++){ if(!exist[i]||mark[fin(i)]) continue; pq.push(sz[fin(i)]); mark[fin(i)] = true; } while(!pq.empty()&&m){ ans+=pq.top()+2; pq.pop(); --m; } cout << ans+2*m-(m%2) << "\n"; return 0; }
#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...