#include "simurgh.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define nxt first
#define idx second
#define ff first
#define ss second
using namespace std;
int nodes, edjes;
vector<pair<int, int> >adj[501];
vector<pair<int, int > >ejes;
vector<int>indicesAns, otros;
vector<int>posibles;
int hoja;
bool yaSeSabia[500*500];
bool checked[501];
int contC = 0;
int repre[501];
int ultimoEje;
//bool vis[501];
void memss(){
//for(int i = 0 ; i < nodes; i ++)vis[i] = false;
}
int findd(int nod){
if(repre[nod] == nod)return nod;
return repre[nod] = findd(repre[nod]);
}
void joinn(int a, int b){
a = findd (a);
b = findd (b);
if(a==b)return;
repre[a] = b;
}
void unir(){
int used = 0;
//cout << " nuevo arbol " << endl;
otros.clear();
posibles.clear();
hoja = -1;
for(int i = 0 ; i < nodes ; i ++)repre[i] = i;
for(int i = 0 ; i < indicesAns.size() ; i ++){
used ++ ;
joinn(ejes[indicesAns[i]].ff, ejes[indicesAns[i]].ss);
//cout << ejes[indicesAns[i]].ff << " join " << ejes[indicesAns[i]].ss << endl;
}
ultimoEje = -1;
for(int i = 0 ; i < edjes ; i ++){
if(findd (ejes[i].ff) == findd(ejes[i].ss)){
yaSeSabia[i] = true;
}
}
for(int i = 0 ; i < edjes ; i ++){
if(findd (ejes[i].ff) != findd(ejes[i].ss)){
if(used < nodes-2){
used ++ ;
otros.pb(i);
joinn(ejes[i].ff, ejes[i].ss);
//cout << ejes[i].ff << " join " << ejes[i].ss << endl;
hoja = checked[ejes[i].ss] ? ejes[i].ff : ejes[i].ss;
}else{
posibles.pb(i);
}
}
}
}
int calculate(vector<pair<int, int> >&resp){
//cout << "probando para " << k << endl;
vector<int>indTest;
indTest = indicesAns;
for(auto i : otros)indTest.pb(i);
int maxi = INT_MIN;
for(int i = 0 ; i < posibles.size() ; i ++){
if(yaSeSabia[posibles[i]])continue;
indTest.pb(posibles[i]);
yaSeSabia[posibles[i]] = true;
resp.pb({posibles[i], count_common_roads( indTest )});
indTest.pop_back();
maxi = max(maxi, resp.back().ss);
}
return maxi;// Ya calcule si estos ejes son o no de la respuesta.
}
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
for(int i = 0 ; i < n; i ++)checked[i] = false;
for(int i = 0 ; i < u.size() ; i ++){
yaSeSabia[i] = false;
}
nodes = n;
edjes = u.size();
for(int i = 0 ; i < edjes ; i ++){
adj[u[i]].pb({v[i], i});
adj[v[i]].pb({u[i], i});
ejes.pb({u[i], v[i]});
}
memss();
while(contC < n){
unir();
vector<pair<int, int> >resp;
int maxi = calculate(resp);
if(maxi == -1)break;
//cout << " gold " << endl;
for(auto i : resp){
if(i.ss == maxi){
//cout << i.ff << endl;
indicesAns.pb(i.ff);
}
}
if(indicesAns.size() == n-1)return indicesAns;
}
return indicesAns;
}
Compilation message
simurgh.cpp: In function 'void unir()':
simurgh.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i = 0 ; i < indicesAns.size() ; i ++){
| ~~^~~~~~~~~~~~~~~~~~~
simurgh.cpp: In function 'int calculate(std::vector<std::pair<int, int> >&)':
simurgh.cpp:81:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for(int i = 0 ; i < posibles.size() ; i ++){
| ~~^~~~~~~~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:94:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int i = 0 ; i < u.size() ; i ++){
| ~~^~~~~~~~~~
simurgh.cpp:118:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
118 | if(indicesAns.size() == n-1)return indicesAns;
| ~~~~~~~~~~~~~~~~~~^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
1 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
316 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
212 KB |
correct |
8 |
Correct |
1 ms |
316 KB |
correct |
9 |
Correct |
1 ms |
320 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
1 ms |
324 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
1 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
316 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
212 KB |
correct |
8 |
Correct |
1 ms |
316 KB |
correct |
9 |
Correct |
1 ms |
320 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
1 ms |
324 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
14 |
Correct |
2 ms |
340 KB |
correct |
15 |
Correct |
2 ms |
340 KB |
correct |
16 |
Correct |
2 ms |
340 KB |
correct |
17 |
Correct |
2 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
2 ms |
340 KB |
correct |
20 |
Correct |
2 ms |
392 KB |
correct |
21 |
Correct |
2 ms |
320 KB |
correct |
22 |
Correct |
2 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
316 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
316 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
1 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
340 KB |
correct |
29 |
Correct |
1 ms |
312 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
340 KB |
correct |
33 |
Correct |
1 ms |
340 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
1 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
316 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
212 KB |
correct |
8 |
Correct |
1 ms |
316 KB |
correct |
9 |
Correct |
1 ms |
320 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
1 ms |
324 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
14 |
Correct |
2 ms |
340 KB |
correct |
15 |
Correct |
2 ms |
340 KB |
correct |
16 |
Correct |
2 ms |
340 KB |
correct |
17 |
Correct |
2 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
2 ms |
340 KB |
correct |
20 |
Correct |
2 ms |
392 KB |
correct |
21 |
Correct |
2 ms |
320 KB |
correct |
22 |
Correct |
2 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
316 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
316 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
1 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
340 KB |
correct |
29 |
Correct |
1 ms |
312 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
340 KB |
correct |
33 |
Correct |
1 ms |
340 KB |
correct |
34 |
Correct |
119 ms |
1824 KB |
correct |
35 |
Correct |
97 ms |
1816 KB |
correct |
36 |
Correct |
74 ms |
1532 KB |
correct |
37 |
Correct |
5 ms |
436 KB |
correct |
38 |
Correct |
95 ms |
1812 KB |
correct |
39 |
Correct |
92 ms |
1684 KB |
correct |
40 |
Correct |
75 ms |
1500 KB |
correct |
41 |
Correct |
58 ms |
1832 KB |
correct |
42 |
Correct |
107 ms |
1824 KB |
correct |
43 |
Correct |
88 ms |
1332 KB |
correct |
44 |
Correct |
75 ms |
1040 KB |
correct |
45 |
Correct |
73 ms |
1032 KB |
correct |
46 |
Correct |
54 ms |
964 KB |
correct |
47 |
Correct |
27 ms |
596 KB |
correct |
48 |
Correct |
3 ms |
392 KB |
correct |
49 |
Correct |
8 ms |
340 KB |
correct |
50 |
Correct |
31 ms |
596 KB |
correct |
51 |
Correct |
70 ms |
1108 KB |
correct |
52 |
Correct |
62 ms |
980 KB |
correct |
53 |
Correct |
54 ms |
980 KB |
correct |
54 |
Correct |
74 ms |
1300 KB |
correct |
55 |
Correct |
73 ms |
1136 KB |
correct |
56 |
Correct |
76 ms |
1228 KB |
correct |
57 |
Correct |
71 ms |
1108 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Incorrect |
78 ms |
5116 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
1 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
316 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
212 KB |
correct |
8 |
Correct |
1 ms |
316 KB |
correct |
9 |
Correct |
1 ms |
320 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
1 ms |
324 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
14 |
Correct |
2 ms |
340 KB |
correct |
15 |
Correct |
2 ms |
340 KB |
correct |
16 |
Correct |
2 ms |
340 KB |
correct |
17 |
Correct |
2 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
2 ms |
340 KB |
correct |
20 |
Correct |
2 ms |
392 KB |
correct |
21 |
Correct |
2 ms |
320 KB |
correct |
22 |
Correct |
2 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
316 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
316 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
1 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
340 KB |
correct |
29 |
Correct |
1 ms |
312 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
340 KB |
correct |
33 |
Correct |
1 ms |
340 KB |
correct |
34 |
Correct |
119 ms |
1824 KB |
correct |
35 |
Correct |
97 ms |
1816 KB |
correct |
36 |
Correct |
74 ms |
1532 KB |
correct |
37 |
Correct |
5 ms |
436 KB |
correct |
38 |
Correct |
95 ms |
1812 KB |
correct |
39 |
Correct |
92 ms |
1684 KB |
correct |
40 |
Correct |
75 ms |
1500 KB |
correct |
41 |
Correct |
58 ms |
1832 KB |
correct |
42 |
Correct |
107 ms |
1824 KB |
correct |
43 |
Correct |
88 ms |
1332 KB |
correct |
44 |
Correct |
75 ms |
1040 KB |
correct |
45 |
Correct |
73 ms |
1032 KB |
correct |
46 |
Correct |
54 ms |
964 KB |
correct |
47 |
Correct |
27 ms |
596 KB |
correct |
48 |
Correct |
3 ms |
392 KB |
correct |
49 |
Correct |
8 ms |
340 KB |
correct |
50 |
Correct |
31 ms |
596 KB |
correct |
51 |
Correct |
70 ms |
1108 KB |
correct |
52 |
Correct |
62 ms |
980 KB |
correct |
53 |
Correct |
54 ms |
980 KB |
correct |
54 |
Correct |
74 ms |
1300 KB |
correct |
55 |
Correct |
73 ms |
1136 KB |
correct |
56 |
Correct |
76 ms |
1228 KB |
correct |
57 |
Correct |
71 ms |
1108 KB |
correct |
58 |
Correct |
1 ms |
212 KB |
correct |
59 |
Correct |
1 ms |
212 KB |
correct |
60 |
Incorrect |
78 ms |
5116 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |