#include "collapse.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Query{
int x, idx;
Query(){}
Query(int x, int idx): x(x), idx(idx){}
};
int n, k, q;
vector<Query> query[5002];
vector<int> link[5002];
int cut;
int ans[5002];
bool visited[5002];
void dfs(int x){
visited[x] = 1;
for(auto y: link[x]){
if(!visited[y]) continue;
if((x <= cut) ^ (y <= cut)) continue;
dfs(y);
}
}
vector<int> simulateCollapse(int N, vector<int> T, vector<int> X, vector<int> Y, vector<int> W, vector<int> P){
n = N, k = (int)T.size(), q = (int)W.size();
for(int i=0; i<q; i++){
query[W[i]].push_back(Query(P[i], i));
}
for(int i=0; i<k; i++){
if(T[i] == 0) link[X[i]].push_back(Y[i]), link[Y[i]].push_back(X[i]);
else{
link[X[i]].erase(find(link[X[i]].begin(), link[X[i]].end(), Y[i]));
link[Y[i]].erase(find(link[Y[i]].begin(), link[Y[i]].end(), X[i]));
}
for(Query qr: query[i]){
cut = qr.x;
fill(visited, visited+n, 0);
for(int i=0; i<n; i++){
if(!visited[i]){
ans[qr.idx]++;
dfs(i);
}
}
}
}
return vector<int> (ans, ans+q);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
972 KB |
Output is correct |
2 |
Runtime error |
307 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
322 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
315 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
972 KB |
Output is correct |
2 |
Runtime error |
307 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |