#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
vector<int> pai, tam;
int find(int x) {
if(pai[x] == x) return x;
return pai[x] = find(pai[x]);
}
void join(int x, int y) {
x = find(x);
y = find(y);
if(tam[x] < tam[y]) {
pai[x] = pai[y];
tam[y] += tam[x];
}
else {
pai[y] = pai[x];
tam[x] += tam[y];
}
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
vector<vector<int>> mark(n);
vector<int> ans;
for(int i = 0; i < n; i++) mark[i].resize(n, -1);
for(int i = 0; i < sz(u); i++) mark[u[i]][v[i]] = mark[v[i]][u[i]] = i;
pai.resize(n);
tam.resize(n);
for(int i = 0; i < n; i++) {
// fixa o vertice que estamos olhando
for(int j = 0; j < n; j++) pai[j] = j, tam[j] = 1;
vector<int> roads, pos(n);
for(int j = 0; j < sz(u); j++){
if(u[j] == i or v[j] == i) continue;
if(find(u[j]) != find(v[j])) join(u[j], v[j]), roads.pb(j);
}
vector<vector<int>> comps(n);
for(int j = 0; j < n; j++)
if(mark[i][j] != -1) comps[find(j)].pb(j);
for(int j = 0; j < n; j++) {
if(comps[j].empty()) continue;
pos[j] = roads.size();
roads.pb(mark[i][comps[j][0]]);
}
// cout << "---------\nCASO " << i << "\n";
// cout << "query:\n";
// for(auto x : roads) cout << u[x] << " " << v[x] << "\n";
int ini = count_common_roads(roads);
//cout << "return: " << ini << "\n";
for(int j = 0; j < n; j++) {
if(comps[j].empty()) continue;
int max_val = ini;
vector<int> add = {comps[j][0]};
for(int k = 1; k < sz(comps[j]); k++) {
roads[pos[j]] = mark[i][comps[j][k]];
// cout << "query:\n";
// for(auto x : roads) cout << u[x] << " " << v[x] << "\n";
int new_val = count_common_roads(roads);
//cout << "return: " << new_val << "\n";
if(new_val > max_val) { add.clear(), add.pb(comps[j][k]), max_val = new_val; }
else if(new_val == max_val) add.pb(comps[j][k]);
}
roads[pos[j]] = mark[i][comps[j][0]];
// cout << "to add:\n";
// for(auto a : add) cout << i <<" " << a << "\n";
for(auto a : add)
if(i < a) ans.pb(mark[i][a]);//, cout << "add " << mark[i][a] << "\n";
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Correct |
1 ms |
348 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
348 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
1 ms |
348 KB |
correct |
10 |
Correct |
0 ms |
348 KB |
correct |
11 |
Correct |
1 ms |
348 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Correct |
1 ms |
348 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
348 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
1 ms |
348 KB |
correct |
10 |
Correct |
0 ms |
348 KB |
correct |
11 |
Correct |
1 ms |
348 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Correct |
2 ms |
344 KB |
correct |
15 |
Correct |
2 ms |
348 KB |
correct |
16 |
Correct |
2 ms |
344 KB |
correct |
17 |
Correct |
2 ms |
344 KB |
correct |
18 |
Correct |
1 ms |
348 KB |
correct |
19 |
Correct |
2 ms |
472 KB |
correct |
20 |
Correct |
2 ms |
468 KB |
correct |
21 |
Correct |
2 ms |
348 KB |
correct |
22 |
Correct |
1 ms |
348 KB |
correct |
23 |
Correct |
1 ms |
436 KB |
correct |
24 |
Correct |
1 ms |
464 KB |
correct |
25 |
Correct |
1 ms |
348 KB |
correct |
26 |
Correct |
2 ms |
348 KB |
correct |
27 |
Correct |
1 ms |
348 KB |
correct |
28 |
Correct |
1 ms |
348 KB |
correct |
29 |
Correct |
1 ms |
348 KB |
correct |
30 |
Correct |
1 ms |
344 KB |
correct |
31 |
Correct |
1 ms |
432 KB |
correct |
32 |
Correct |
1 ms |
348 KB |
correct |
33 |
Correct |
1 ms |
348 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Correct |
1 ms |
348 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
348 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
1 ms |
348 KB |
correct |
10 |
Correct |
0 ms |
348 KB |
correct |
11 |
Correct |
1 ms |
348 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Correct |
2 ms |
344 KB |
correct |
15 |
Correct |
2 ms |
348 KB |
correct |
16 |
Correct |
2 ms |
344 KB |
correct |
17 |
Correct |
2 ms |
344 KB |
correct |
18 |
Correct |
1 ms |
348 KB |
correct |
19 |
Correct |
2 ms |
472 KB |
correct |
20 |
Correct |
2 ms |
468 KB |
correct |
21 |
Correct |
2 ms |
348 KB |
correct |
22 |
Correct |
1 ms |
348 KB |
correct |
23 |
Correct |
1 ms |
436 KB |
correct |
24 |
Correct |
1 ms |
464 KB |
correct |
25 |
Correct |
1 ms |
348 KB |
correct |
26 |
Correct |
2 ms |
348 KB |
correct |
27 |
Correct |
1 ms |
348 KB |
correct |
28 |
Correct |
1 ms |
348 KB |
correct |
29 |
Correct |
1 ms |
348 KB |
correct |
30 |
Correct |
1 ms |
344 KB |
correct |
31 |
Correct |
1 ms |
432 KB |
correct |
32 |
Correct |
1 ms |
348 KB |
correct |
33 |
Correct |
1 ms |
348 KB |
correct |
34 |
Incorrect |
85 ms |
1112 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
344 KB |
correct |
3 |
Incorrect |
72 ms |
2908 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Correct |
1 ms |
348 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
348 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
1 ms |
348 KB |
correct |
10 |
Correct |
0 ms |
348 KB |
correct |
11 |
Correct |
1 ms |
348 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Correct |
2 ms |
344 KB |
correct |
15 |
Correct |
2 ms |
348 KB |
correct |
16 |
Correct |
2 ms |
344 KB |
correct |
17 |
Correct |
2 ms |
344 KB |
correct |
18 |
Correct |
1 ms |
348 KB |
correct |
19 |
Correct |
2 ms |
472 KB |
correct |
20 |
Correct |
2 ms |
468 KB |
correct |
21 |
Correct |
2 ms |
348 KB |
correct |
22 |
Correct |
1 ms |
348 KB |
correct |
23 |
Correct |
1 ms |
436 KB |
correct |
24 |
Correct |
1 ms |
464 KB |
correct |
25 |
Correct |
1 ms |
348 KB |
correct |
26 |
Correct |
2 ms |
348 KB |
correct |
27 |
Correct |
1 ms |
348 KB |
correct |
28 |
Correct |
1 ms |
348 KB |
correct |
29 |
Correct |
1 ms |
348 KB |
correct |
30 |
Correct |
1 ms |
344 KB |
correct |
31 |
Correct |
1 ms |
432 KB |
correct |
32 |
Correct |
1 ms |
348 KB |
correct |
33 |
Correct |
1 ms |
348 KB |
correct |
34 |
Incorrect |
85 ms |
1112 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |