#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;
int N;
const int dydis = 251;
vector<pair<int, int> > brn;
vector<int> zn(dydis * dydis, -1);
vector<pair<int, int> > gr[dydis];
vector<int> tikrai;
int tevas[dydis];
int fP(int v){
if(tevas[v] == v) return v;
return tevas[v] = fP(tevas[v]);
}
void conn(int a, int b){
a = fP(a);
b = fP(b);
if(a == b) return;
tevas[a] = b;
}
set<int> virs;
bool vis[dydis] = {0};
int deg[dydis] = {0};
void form(){
for(int i = 0; i < N; i++) {
gr[i].clear();
vis[i] = 0;
deg[i] = 0;
}
virs.clear();
// cout << "grafas:\n";
for(int i = 0; i < (int) brn.size(); i++){
if(zn[i] != -1) continue;
int a = fP(brn[i].first);
int b = fP(brn[i].second);
if(a == b) continue;
gr[a].push_back({b, i});
gr[b].push_back({a, i});
// cout << a << " -- " << b << endl;
virs.insert(a); virs.insert(b);
}
//cout << endl;
}
vector<int> pl;
void dfs(int v){
vis[v] = 1;
for(auto x : gr[v]){
if(vis[x.first]) continue;
pl.push_back(x.second);
deg[v]++;
deg[x.first]++;
dfs(x.first);
}
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
//count_common_roads
N = n;
vector<int> ret;
for(int i = 0; i < N; i++) tevas[i] = i;
for(int i = 0; i < (int)u.size(); i++) {
brn.push_back({u[i], v[i]});
}
int it = 0;
while((int) tikrai.size() != n-1){
pl.clear();
form();
int v = *virs.begin();
dfs(v);
int u = -1;
for(int i = 0; i < n; i++) if(deg[i] == 1) u = i;
// cout << "komponentai: \n"; for(int i = 0; i < n; i++) cout << i << ": " << fP(i) << endl; cout << endl;
// cout << "suformuoju medi: \n"; for(int i = 0; i < pl.size(); i++) cout << brn[pl[i]].first << " - > " << brn[pl[i]].second << endl;
// cout << "\nmedzio lapas: " << u << endl;
// cout << endl;
vector<int> rest;
for(int i = 0; i < (int)pl.size(); i++){
int a = fP(brn[pl[i]].first);
int b = fP(brn[pl[i]].second);
if(a == u || b == u){
continue;
}
rest.push_back(pl[i]);
}
for(auto x : tikrai) rest.push_back(x);
vector<pair<int, int> > aa;
int mx = 0;
for(auto x : gr[u]){
rest.push_back(x.second);
int cm = count_common_roads(rest);
aa.push_back({cm, x.second});
mx = max(mx, cm);
rest.pop_back();
}
for(auto x : aa){
if(x.first == mx) {
tikrai.push_back(x.second);
zn[x.second] = 1;
conn(brn[x.second].first, brn[x.second].second);
// cout << brn[x.second].first << " -> " << brn[x.second].second << " tikrai geras" << endl;
}else{
zn[x.second] = 0;
// cout << brn[x.second].first << " -> " << brn[x.second].second << " tikrai blogas" << endl;
}
}
}
return tikrai;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:65:6: warning: unused variable 'it' [-Wunused-variable]
65 | int it = 0;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
correct |
2 |
Correct |
1 ms |
460 KB |
correct |
3 |
Correct |
1 ms |
564 KB |
correct |
4 |
Correct |
1 ms |
460 KB |
correct |
5 |
Correct |
1 ms |
460 KB |
correct |
6 |
Correct |
1 ms |
460 KB |
correct |
7 |
Correct |
1 ms |
460 KB |
correct |
8 |
Correct |
1 ms |
460 KB |
correct |
9 |
Correct |
1 ms |
460 KB |
correct |
10 |
Correct |
1 ms |
460 KB |
correct |
11 |
Correct |
1 ms |
460 KB |
correct |
12 |
Correct |
1 ms |
460 KB |
correct |
13 |
Correct |
1 ms |
460 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
correct |
2 |
Correct |
1 ms |
460 KB |
correct |
3 |
Correct |
1 ms |
564 KB |
correct |
4 |
Correct |
1 ms |
460 KB |
correct |
5 |
Correct |
1 ms |
460 KB |
correct |
6 |
Correct |
1 ms |
460 KB |
correct |
7 |
Correct |
1 ms |
460 KB |
correct |
8 |
Correct |
1 ms |
460 KB |
correct |
9 |
Correct |
1 ms |
460 KB |
correct |
10 |
Correct |
1 ms |
460 KB |
correct |
11 |
Correct |
1 ms |
460 KB |
correct |
12 |
Correct |
1 ms |
460 KB |
correct |
13 |
Correct |
1 ms |
460 KB |
correct |
14 |
Correct |
4 ms |
564 KB |
correct |
15 |
Correct |
4 ms |
588 KB |
correct |
16 |
Correct |
4 ms |
564 KB |
correct |
17 |
Correct |
4 ms |
560 KB |
correct |
18 |
Correct |
2 ms |
560 KB |
correct |
19 |
Correct |
3 ms |
588 KB |
correct |
20 |
Correct |
4 ms |
588 KB |
correct |
21 |
Correct |
4 ms |
632 KB |
correct |
22 |
Correct |
3 ms |
588 KB |
correct |
23 |
Correct |
3 ms |
588 KB |
correct |
24 |
Correct |
2 ms |
588 KB |
correct |
25 |
Correct |
1 ms |
460 KB |
correct |
26 |
Correct |
2 ms |
588 KB |
correct |
27 |
Correct |
3 ms |
588 KB |
correct |
28 |
Correct |
2 ms |
564 KB |
correct |
29 |
Correct |
1 ms |
556 KB |
correct |
30 |
Correct |
2 ms |
588 KB |
correct |
31 |
Correct |
2 ms |
588 KB |
correct |
32 |
Correct |
2 ms |
588 KB |
correct |
33 |
Correct |
2 ms |
588 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
correct |
2 |
Correct |
1 ms |
460 KB |
correct |
3 |
Correct |
1 ms |
564 KB |
correct |
4 |
Correct |
1 ms |
460 KB |
correct |
5 |
Correct |
1 ms |
460 KB |
correct |
6 |
Correct |
1 ms |
460 KB |
correct |
7 |
Correct |
1 ms |
460 KB |
correct |
8 |
Correct |
1 ms |
460 KB |
correct |
9 |
Correct |
1 ms |
460 KB |
correct |
10 |
Correct |
1 ms |
460 KB |
correct |
11 |
Correct |
1 ms |
460 KB |
correct |
12 |
Correct |
1 ms |
460 KB |
correct |
13 |
Correct |
1 ms |
460 KB |
correct |
14 |
Correct |
4 ms |
564 KB |
correct |
15 |
Correct |
4 ms |
588 KB |
correct |
16 |
Correct |
4 ms |
564 KB |
correct |
17 |
Correct |
4 ms |
560 KB |
correct |
18 |
Correct |
2 ms |
560 KB |
correct |
19 |
Correct |
3 ms |
588 KB |
correct |
20 |
Correct |
4 ms |
588 KB |
correct |
21 |
Correct |
4 ms |
632 KB |
correct |
22 |
Correct |
3 ms |
588 KB |
correct |
23 |
Correct |
3 ms |
588 KB |
correct |
24 |
Correct |
2 ms |
588 KB |
correct |
25 |
Correct |
1 ms |
460 KB |
correct |
26 |
Correct |
2 ms |
588 KB |
correct |
27 |
Correct |
3 ms |
588 KB |
correct |
28 |
Correct |
2 ms |
564 KB |
correct |
29 |
Correct |
1 ms |
556 KB |
correct |
30 |
Correct |
2 ms |
588 KB |
correct |
31 |
Correct |
2 ms |
588 KB |
correct |
32 |
Correct |
2 ms |
588 KB |
correct |
33 |
Correct |
2 ms |
588 KB |
correct |
34 |
Correct |
422 ms |
2928 KB |
correct |
35 |
Correct |
390 ms |
2596 KB |
correct |
36 |
Correct |
260 ms |
2156 KB |
correct |
37 |
Correct |
21 ms |
672 KB |
correct |
38 |
Correct |
375 ms |
2572 KB |
correct |
39 |
Correct |
309 ms |
2188 KB |
correct |
40 |
Correct |
301 ms |
2704 KB |
correct |
41 |
Correct |
30 ms |
2040 KB |
correct |
42 |
Correct |
365 ms |
2012 KB |
correct |
43 |
Correct |
228 ms |
1532 KB |
correct |
44 |
Correct |
181 ms |
1344 KB |
correct |
45 |
Correct |
201 ms |
1352 KB |
correct |
46 |
Correct |
154 ms |
1316 KB |
correct |
47 |
Correct |
79 ms |
880 KB |
correct |
48 |
Correct |
10 ms |
556 KB |
correct |
49 |
Correct |
22 ms |
588 KB |
correct |
50 |
Correct |
67 ms |
868 KB |
correct |
51 |
Correct |
197 ms |
1316 KB |
correct |
52 |
Correct |
179 ms |
1488 KB |
correct |
53 |
Correct |
157 ms |
1168 KB |
correct |
54 |
Correct |
212 ms |
1548 KB |
correct |
55 |
Correct |
200 ms |
1456 KB |
correct |
56 |
Correct |
197 ms |
1596 KB |
correct |
57 |
Correct |
195 ms |
1476 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
correct |
2 |
Correct |
1 ms |
460 KB |
correct |
3 |
Runtime error |
23 ms |
5492 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
correct |
2 |
Correct |
1 ms |
460 KB |
correct |
3 |
Correct |
1 ms |
564 KB |
correct |
4 |
Correct |
1 ms |
460 KB |
correct |
5 |
Correct |
1 ms |
460 KB |
correct |
6 |
Correct |
1 ms |
460 KB |
correct |
7 |
Correct |
1 ms |
460 KB |
correct |
8 |
Correct |
1 ms |
460 KB |
correct |
9 |
Correct |
1 ms |
460 KB |
correct |
10 |
Correct |
1 ms |
460 KB |
correct |
11 |
Correct |
1 ms |
460 KB |
correct |
12 |
Correct |
1 ms |
460 KB |
correct |
13 |
Correct |
1 ms |
460 KB |
correct |
14 |
Correct |
4 ms |
564 KB |
correct |
15 |
Correct |
4 ms |
588 KB |
correct |
16 |
Correct |
4 ms |
564 KB |
correct |
17 |
Correct |
4 ms |
560 KB |
correct |
18 |
Correct |
2 ms |
560 KB |
correct |
19 |
Correct |
3 ms |
588 KB |
correct |
20 |
Correct |
4 ms |
588 KB |
correct |
21 |
Correct |
4 ms |
632 KB |
correct |
22 |
Correct |
3 ms |
588 KB |
correct |
23 |
Correct |
3 ms |
588 KB |
correct |
24 |
Correct |
2 ms |
588 KB |
correct |
25 |
Correct |
1 ms |
460 KB |
correct |
26 |
Correct |
2 ms |
588 KB |
correct |
27 |
Correct |
3 ms |
588 KB |
correct |
28 |
Correct |
2 ms |
564 KB |
correct |
29 |
Correct |
1 ms |
556 KB |
correct |
30 |
Correct |
2 ms |
588 KB |
correct |
31 |
Correct |
2 ms |
588 KB |
correct |
32 |
Correct |
2 ms |
588 KB |
correct |
33 |
Correct |
2 ms |
588 KB |
correct |
34 |
Correct |
422 ms |
2928 KB |
correct |
35 |
Correct |
390 ms |
2596 KB |
correct |
36 |
Correct |
260 ms |
2156 KB |
correct |
37 |
Correct |
21 ms |
672 KB |
correct |
38 |
Correct |
375 ms |
2572 KB |
correct |
39 |
Correct |
309 ms |
2188 KB |
correct |
40 |
Correct |
301 ms |
2704 KB |
correct |
41 |
Correct |
30 ms |
2040 KB |
correct |
42 |
Correct |
365 ms |
2012 KB |
correct |
43 |
Correct |
228 ms |
1532 KB |
correct |
44 |
Correct |
181 ms |
1344 KB |
correct |
45 |
Correct |
201 ms |
1352 KB |
correct |
46 |
Correct |
154 ms |
1316 KB |
correct |
47 |
Correct |
79 ms |
880 KB |
correct |
48 |
Correct |
10 ms |
556 KB |
correct |
49 |
Correct |
22 ms |
588 KB |
correct |
50 |
Correct |
67 ms |
868 KB |
correct |
51 |
Correct |
197 ms |
1316 KB |
correct |
52 |
Correct |
179 ms |
1488 KB |
correct |
53 |
Correct |
157 ms |
1168 KB |
correct |
54 |
Correct |
212 ms |
1548 KB |
correct |
55 |
Correct |
200 ms |
1456 KB |
correct |
56 |
Correct |
197 ms |
1596 KB |
correct |
57 |
Correct |
195 ms |
1476 KB |
correct |
58 |
Correct |
1 ms |
460 KB |
correct |
59 |
Correct |
1 ms |
460 KB |
correct |
60 |
Runtime error |
23 ms |
5492 KB |
Execution killed with signal 11 |
61 |
Halted |
0 ms |
0 KB |
- |