#include<bits/stdc++.h>
using namespace std;
const int N=2000009;
int a,b,c,d,e,i,j,ii,jj,zx,xc,pi,fx[N],f[N],pas,bo[N],zm[N],li;
pair <int, int> P[N],p[N];
int l[N];
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>a>>b;
for(i=1; i<=a; i++){
cin>>P[i].first>>P[i].second;
pi++;p[pi].first=P[i].first;p[pi].second=P[i].second;
pi++;p[pi].first=P[i].second;p[pi].second=P[i].first;
}
sort(p+1,p+pi+1);
zx=1;
fx[0]=zx;
for(i=1; i<=pi; i++){
zx++;
fx[p[i].first]=zx;
}
for(i=1; i<=pi; i++){
f[i]=fx[p[i].second];
}
pas=0;
for(i=1; i<=pi; i++){
if(bo[i]!=0) continue;
c=i;
while(bo[c]==0&&c!=0){
bo[c]=1;c=f[c];zm[i]++;
}
if(i==1){
pas=zm[i]-1;
}else{
li++;
l[li]=zm[i];
}
}
sort(l+1,l+li+1);
while(b>0&&li>0){
pas+=l[li]+2;b--;li--;
}
pas+=b*2;
cout<<pas;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
584 KB |
Output is correct |
2 |
Correct |
5 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
10044 KB |
Output is correct |
2 |
Correct |
153 ms |
25540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
18332 KB |
Output is correct |
2 |
Incorrect |
270 ms |
36088 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
326 ms |
48056 KB |
Output is correct |
2 |
Correct |
379 ms |
56236 KB |
Output is correct |
3 |
Correct |
424 ms |
60208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
482 ms |
63556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
556 ms |
65536 KB |
Output is correct |
2 |
Correct |
524 ms |
65536 KB |
Output is correct |
3 |
Correct |
398 ms |
65536 KB |
Output is correct |
4 |
Correct |
486 ms |
65536 KB |
Output is correct |