제출 #262168

#제출 시각아이디문제언어결과실행 시간메모리
262168WLZTeleporters (IOI08_teleporters)C++14
75 / 100
1099 ms65536 KiB
#include <bits/stdc++.h> using namespace std; int n, m; vector< vector<int> > g; vector<bool> was; int sz = 0; map<int, int> other; vector<int> a; void dfs(int u) { was[u] = true; if (u == 2 * n) { return; } sz++; int next = upper_bound(a.begin(), a.end(), other[a[u]]) - a.begin(); if (!was[next]) { dfs(next); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) { int w, e; cin >> w >> e; other[w] = e; other[e] = w; a.push_back(e); a.push_back(w); } sort(a.begin(), a.end()); was.assign(2 * n + 1, false); dfs(0); int ans = sz; vector<int> b; for (int i = 0; i < 2 * n; i++) { if (!was[i]) { sz = 0; dfs(i); b.push_back(sz); } } sort(b.rbegin(), b.rend()); for (int i = 0; i < min(m, (int) b.size()); i++) { ans += b[i] + 2; } m -= min(m, (int) b.size()); while (m > 0) { ans++; m--; if (m > 0) { ans += 3; m--; } } cout << ans << '\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...