# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
56767 | win11905 | Teleporters (IOI08_teleporters) | C++11 | 795 ms | 66560 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 pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 2e6+5;
int n, m, psz, pz1;
bool Check[N];
int main() {
vector<int> V(N), val(N), neibour(N), Com(N);
scanf("%d %d", &n, &m);
for(int i = 0, u, v; i < n; ++i) {
scanf("%d %d", &u, &v);
neibour[u] = v, neibour[v] = u;
V[u]++, V[v]++;
}
for(int i = 1; i < N; ++i) {
V[i] += V[i-1];
if(V[i] != V[i-1]) Com[pz1++] = i;
}
int cnt = 0, p = 0; Check[0] = true;
while(p != (n<<1)) Check[p = V[neibour[Com[p]]]] = true, cnt++;
for(int i = 1; i <= (n<<1); ++i) if(!Check[i]) {
int u = i, sz = 0; Check[u] = true;
do Check[u = V[neibour[Com[u]]]] = true, sz++; while(u != i);
val[++psz] = sz;
}
sort(val.begin()+1, val.begin() + psz + 1, greater<int>()); for(int i = 1; i <= psz; ++i) val[i] += val[i-1];
cnt += val[min(psz, m)] + 2 * min(psz, m);
if(m > psz) m -= psz, cnt += ((m>>1)<<2) + (m & 1);
printf("%d\n", cnt);
}
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... |