#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> U, V;
map<vector<int>, int> M;
vector<int> R;
int find(int v){
if(v==R[v])return v;
return R[v]=find(R[v]);
}
void Union(int u, int v){
R[u]=v;
}
bool check(vector<int> v){
R.resize(n);
iota(R.begin(), R.end(), 0);
if(v.size()!=n-1)return 0;
for(int i:v){
int u=find(U[i]), v=find(V[i]);
if(u==v)return 0;
Union(u ,v);
}
return 1;
}
int count(vector<int> v){
//cout<<v.size()<<"\n";
assert(check(v));
sort(v.begin(), v.end());
if(M.find(v)==M.end()) M[v]=count_common_roads(v);
return M[v];
}
int spe;
vector<int> V2[505];
vector<int> span(vector<int> &kol){
R.resize(n);
iota(R.begin(), R.end(), 0);
vector<int> ans;
for(int i:kol){
//cout<<U[i]<<" "<<V[i]<<endl;
int u=find(U[i]), v=find(V[i]);
if(U[i]==spe)V2[v].push_back(i);
else if(V[i]==spe)V2[u].push_back(i);
else if(u!=v){
//cout<<u<<" "<<v<<"w\n";
Union(u, v);
ans.push_back(i);
}
}
return ans;
}
vector<int> dobre;
std::vector<int> find_roads(int _n, std::vector<int> u2, std::vector<int> v2) {
U=u2;
V=v2;
n=_n;
int m=U.size();
vector<int> edg(m);
iota(edg.begin(), edg.end(), 0);
for(int i=0; i<n; i++){
int k=edg.size()-1;
for(int j=0; j<k; j++){
if(U[edg[j]]==i || V[edg[j]]==i){
while(k>=0 && (U[edg[k]]==i || V[edg[k]]==i))k--;
if(j>k)break;
swap(edg[j], edg[k]);
}
}
spe=i;
for(int j=0; j<n; j++)V2[j].clear();
vector<int> tre=span(edg);
/*bool b=1;
for(int j=0; j<tre.size()-1; j++){
if((U[tre[j]]==i || V[tre[j]]==i)){
swap(tre[j], tre.back());
}
}
for(int j=0; j<tre.size()-1; j++){
if((U[tre[j]]==i || V[tre[j]]==i)){
b=0;
}
}
if(b){*/
//cout<<i<<" a"<<endl;
vector<int> gdzie;
for(int j=0; j<n; j++){
if(V2[j].size()){
//cout<<"b";
gdzie.push_back(j);
tre.push_back(V2[j].back());
}
}
//cout<<tre.size()<<"\n";
for(int k=0; k<gdzie.size(); k++){
vector<int> ans;
int M=0;
//cout<<tre[0]<<" "<<tre[1]<<" "<<" b\n";
for(int j:V2[gdzie[k]]){
//cout<<j<<"\n";
if(U[j]==i || V[j]==i){
tre[n-1-gdzie.size()+k]=j;
//cout<<tre[0]<<" "<<tre[1]<<" "<<tre[2]<<"\n";
ans.push_back(count(tre));
M=max(M, ans.back());
//cout<<j<<" "<<ans.back()<<"\n";
}
}
int cnt=0;
deque<int> todo;
for(int j:V2[gdzie[k]]){
//if(U[edg[j]]==i || V[edg[j]]==i){
if(ans[cnt]<M){
todo.push_back(j);
//cout<<todo.back()<<"q ";
}
cnt++;
//}
}
vector<int> edg2;
for(int j=0; j<edg.size(); j++){
if(todo.size() && edg[j]==todo.front()){
todo.pop_front();
}
else edg2.push_back(edg[j]);
}
edg=edg2;
//cout<<"\n";
}
}
//for(int j:edg)cout<<j<<" ";
assert(edg.size()==n-1);
assert(count(edg)==n-1);
sort(edg.begin(), edg.end());
return edg;
}
Compilation message
simurgh.cpp: In function 'bool check(std::vector<int>)':
simurgh.cpp:19:13: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
19 | if(v.size()!=n-1)return 0;
| ~~~~~~~~^~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:95:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int k=0; k<gdzie.size(); k++){
| ~^~~~~~~~~~~~~
simurgh.cpp:121:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
121 | for(int j=0; j<edg.size(); j++){
| ~^~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from simurgh.cpp:2:
simurgh.cpp:132:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
132 | assert(edg.size()==n-1);
| ~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Correct |
1 ms |
300 KB |
correct |
4 |
Correct |
1 ms |
204 KB |
correct |
5 |
Correct |
1 ms |
300 KB |
correct |
6 |
Correct |
1 ms |
204 KB |
correct |
7 |
Correct |
1 ms |
204 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
1 ms |
308 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
1 ms |
204 KB |
correct |
13 |
Correct |
1 ms |
204 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Correct |
1 ms |
300 KB |
correct |
4 |
Correct |
1 ms |
204 KB |
correct |
5 |
Correct |
1 ms |
300 KB |
correct |
6 |
Correct |
1 ms |
204 KB |
correct |
7 |
Correct |
1 ms |
204 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
1 ms |
308 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
1 ms |
204 KB |
correct |
13 |
Correct |
1 ms |
204 KB |
correct |
14 |
Correct |
7 ms |
588 KB |
correct |
15 |
Correct |
7 ms |
588 KB |
correct |
16 |
Correct |
7 ms |
588 KB |
correct |
17 |
Correct |
6 ms |
588 KB |
correct |
18 |
Correct |
3 ms |
332 KB |
correct |
19 |
Correct |
7 ms |
640 KB |
correct |
20 |
Correct |
6 ms |
588 KB |
correct |
21 |
Correct |
6 ms |
588 KB |
correct |
22 |
Correct |
5 ms |
460 KB |
correct |
23 |
Correct |
4 ms |
428 KB |
correct |
24 |
Correct |
5 ms |
460 KB |
correct |
25 |
Correct |
2 ms |
332 KB |
correct |
26 |
Correct |
4 ms |
460 KB |
correct |
27 |
Correct |
5 ms |
484 KB |
correct |
28 |
Correct |
2 ms |
332 KB |
correct |
29 |
Correct |
2 ms |
332 KB |
correct |
30 |
Correct |
4 ms |
460 KB |
correct |
31 |
Correct |
4 ms |
460 KB |
correct |
32 |
Correct |
4 ms |
460 KB |
correct |
33 |
Correct |
5 ms |
460 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Correct |
1 ms |
300 KB |
correct |
4 |
Correct |
1 ms |
204 KB |
correct |
5 |
Correct |
1 ms |
300 KB |
correct |
6 |
Correct |
1 ms |
204 KB |
correct |
7 |
Correct |
1 ms |
204 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
1 ms |
308 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
1 ms |
204 KB |
correct |
13 |
Correct |
1 ms |
204 KB |
correct |
14 |
Correct |
7 ms |
588 KB |
correct |
15 |
Correct |
7 ms |
588 KB |
correct |
16 |
Correct |
7 ms |
588 KB |
correct |
17 |
Correct |
6 ms |
588 KB |
correct |
18 |
Correct |
3 ms |
332 KB |
correct |
19 |
Correct |
7 ms |
640 KB |
correct |
20 |
Correct |
6 ms |
588 KB |
correct |
21 |
Correct |
6 ms |
588 KB |
correct |
22 |
Correct |
5 ms |
460 KB |
correct |
23 |
Correct |
4 ms |
428 KB |
correct |
24 |
Correct |
5 ms |
460 KB |
correct |
25 |
Correct |
2 ms |
332 KB |
correct |
26 |
Correct |
4 ms |
460 KB |
correct |
27 |
Correct |
5 ms |
484 KB |
correct |
28 |
Correct |
2 ms |
332 KB |
correct |
29 |
Correct |
2 ms |
332 KB |
correct |
30 |
Correct |
4 ms |
460 KB |
correct |
31 |
Correct |
4 ms |
460 KB |
correct |
32 |
Correct |
4 ms |
460 KB |
correct |
33 |
Correct |
5 ms |
460 KB |
correct |
34 |
Correct |
702 ms |
30984 KB |
correct |
35 |
Correct |
706 ms |
29940 KB |
correct |
36 |
Correct |
496 ms |
20604 KB |
correct |
37 |
Correct |
36 ms |
1604 KB |
correct |
38 |
Correct |
712 ms |
30816 KB |
correct |
39 |
Correct |
599 ms |
26288 KB |
correct |
40 |
Correct |
466 ms |
20720 KB |
correct |
41 |
Correct |
713 ms |
30980 KB |
correct |
42 |
Correct |
722 ms |
30708 KB |
correct |
43 |
Correct |
368 ms |
16660 KB |
correct |
44 |
Correct |
287 ms |
13328 KB |
correct |
45 |
Correct |
346 ms |
15628 KB |
correct |
46 |
Correct |
271 ms |
11916 KB |
correct |
47 |
Correct |
114 ms |
5332 KB |
correct |
48 |
Correct |
21 ms |
632 KB |
correct |
49 |
Correct |
37 ms |
1728 KB |
correct |
50 |
Correct |
112 ms |
5332 KB |
correct |
51 |
Correct |
341 ms |
15756 KB |
correct |
52 |
Correct |
294 ms |
13300 KB |
correct |
53 |
Correct |
268 ms |
11796 KB |
correct |
54 |
Correct |
371 ms |
16536 KB |
correct |
55 |
Correct |
334 ms |
15740 KB |
correct |
56 |
Correct |
335 ms |
15728 KB |
correct |
57 |
Correct |
334 ms |
15752 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Incorrect |
526 ms |
23560 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Correct |
1 ms |
300 KB |
correct |
4 |
Correct |
1 ms |
204 KB |
correct |
5 |
Correct |
1 ms |
300 KB |
correct |
6 |
Correct |
1 ms |
204 KB |
correct |
7 |
Correct |
1 ms |
204 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
1 ms |
308 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
1 ms |
204 KB |
correct |
13 |
Correct |
1 ms |
204 KB |
correct |
14 |
Correct |
7 ms |
588 KB |
correct |
15 |
Correct |
7 ms |
588 KB |
correct |
16 |
Correct |
7 ms |
588 KB |
correct |
17 |
Correct |
6 ms |
588 KB |
correct |
18 |
Correct |
3 ms |
332 KB |
correct |
19 |
Correct |
7 ms |
640 KB |
correct |
20 |
Correct |
6 ms |
588 KB |
correct |
21 |
Correct |
6 ms |
588 KB |
correct |
22 |
Correct |
5 ms |
460 KB |
correct |
23 |
Correct |
4 ms |
428 KB |
correct |
24 |
Correct |
5 ms |
460 KB |
correct |
25 |
Correct |
2 ms |
332 KB |
correct |
26 |
Correct |
4 ms |
460 KB |
correct |
27 |
Correct |
5 ms |
484 KB |
correct |
28 |
Correct |
2 ms |
332 KB |
correct |
29 |
Correct |
2 ms |
332 KB |
correct |
30 |
Correct |
4 ms |
460 KB |
correct |
31 |
Correct |
4 ms |
460 KB |
correct |
32 |
Correct |
4 ms |
460 KB |
correct |
33 |
Correct |
5 ms |
460 KB |
correct |
34 |
Correct |
702 ms |
30984 KB |
correct |
35 |
Correct |
706 ms |
29940 KB |
correct |
36 |
Correct |
496 ms |
20604 KB |
correct |
37 |
Correct |
36 ms |
1604 KB |
correct |
38 |
Correct |
712 ms |
30816 KB |
correct |
39 |
Correct |
599 ms |
26288 KB |
correct |
40 |
Correct |
466 ms |
20720 KB |
correct |
41 |
Correct |
713 ms |
30980 KB |
correct |
42 |
Correct |
722 ms |
30708 KB |
correct |
43 |
Correct |
368 ms |
16660 KB |
correct |
44 |
Correct |
287 ms |
13328 KB |
correct |
45 |
Correct |
346 ms |
15628 KB |
correct |
46 |
Correct |
271 ms |
11916 KB |
correct |
47 |
Correct |
114 ms |
5332 KB |
correct |
48 |
Correct |
21 ms |
632 KB |
correct |
49 |
Correct |
37 ms |
1728 KB |
correct |
50 |
Correct |
112 ms |
5332 KB |
correct |
51 |
Correct |
341 ms |
15756 KB |
correct |
52 |
Correct |
294 ms |
13300 KB |
correct |
53 |
Correct |
268 ms |
11796 KB |
correct |
54 |
Correct |
371 ms |
16536 KB |
correct |
55 |
Correct |
334 ms |
15740 KB |
correct |
56 |
Correct |
335 ms |
15728 KB |
correct |
57 |
Correct |
334 ms |
15752 KB |
correct |
58 |
Correct |
1 ms |
204 KB |
correct |
59 |
Correct |
1 ms |
204 KB |
correct |
60 |
Incorrect |
526 ms |
23560 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |