#include "collapse.h"
#include <bits/stdc++.h>
#define ep insert
#define F first
#define S second
using namespace std;
const int N=5005;
int n,q,m,par[N],sz[N],c;
int getpar(int x){
if (par[x]==x) return x;
return par[x]=getpar(par[x]);
}
bool link(int x,int y){
x=getpar(x);y=getpar(y);
if (x==y) return 0;
if (sz[x]>sz[y]) swap(x,y);
sz[y]+=sz[x];
par[x]=y;
return 1;
}
std::vector<int> simulateCollapse(
int NN,
std::vector<int> t,
std::vector<int> x,
std::vector<int> y,
std::vector<int> w,
std::vector<int> p
) {
n=NN;c=x.size();q=w.size();
vector<int> ans(q);
for (int k=0;k<q;k++){
for (int i=0;i<n;i++) par[i]=i,sz[i]=1;
int comp=n;
set<pair<int,int>> s;
for (int i=0;i<c;i++){
if (x[i]<=p[k] && y[i]>p[k]) continue;
if (y[i]<=p[k] && x[i]>p[k]) continue;
if (t[i]) s.erase({x[i],y[i]});
else s.ep({x[i],y[i]});
}
for (auto u:s){
int xx=u.F,yy=u.S;
comp-=link(xx,yy);
}
ans[k]=comp;
}return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
600 KB |
Output is correct |
2 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2624 KB |
Output is correct |
2 |
Incorrect |
25 ms |
2648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2624 KB |
Output is correct |
2 |
Incorrect |
29 ms |
2648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
600 KB |
Output is correct |
2 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |