#include<bits/stdc++.h>
#include "simurgh.h"
using namespace std;
const int nax = 500;
vector<pair<int,int>>g[nax];
int m;
vector<int>stk;
bool vis[nax];
int sz[nax], par[nax];
vector<int>grp[nax];
int where[nax*nax];
int find(int v) {
return par[v] = (v==par[v]) ? v : find(par[v]);
}
void unite(int u, int v) {
u = find(u), v = find(v);
if(sz[u]<sz[v]) swap(u, v);
sz[u] += sz[v];
par[v] = u;
}
void dfs(int v, int ban) {
vis[v] = 1;
for(auto &[c, e] : g[v]) if(c!=ban && !vis[c]) {
stk.push_back(e);
unite(v, c);
dfs(c, ban);
}
}
vector<int>find_roads(int n, vector<int>u, vector<int>v) {
m = u.size();
for(int i=0; i<m; ++i) {
g[u[i]].emplace_back(v[i], i);
g[v[i]].emplace_back(u[i], i);
}
vector<int>royal;
for(int ban=0; ban<n; ++ban) {
stk.clear();
for(int i=0; i<n; ++i) {
vis[i] = 0;
sz[i] = 1, par[i] = i;
grp[i].clear();
}
for(int i=0; i<n; ++i) {
if(i!=ban && !vis[i]) {
dfs(i, ban);
}
}
for(auto &[c, e] : g[ban]) {
grp[find(c)].push_back(e);
}
for(int i=0; i<n; ++i) if(!grp[i].empty()) {
where[grp[i][0]] = stk.size();
stk.push_back(grp[i][0]);
}
for(int i=0; i<n; ++i) if(!grp[i].empty()) {
vector<int>res;
int pos = where[grp[i][0]];
for(int x : grp[i]) {
stk[pos] = x;
res.push_back(count_common_roads(stk));
}
int mx = *max_element(res.begin(), res.end());
for(int j=0; j<grp[i].size(); ++j) {
if(res[j]==mx) {
royal.push_back(grp[i][j]);
}
}
}
}
sort(royal.begin(), royal.end());
royal.resize(unique(royal.begin(), royal.end())-royal.begin());
// for(int x : royal) cerr<<x<<' ';
// cerr<<'\n';
return royal;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:72:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int j=0; j<grp[i].size(); ++j) {
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Correct |
1 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
340 KB |
correct |
5 |
Correct |
1 ms |
336 KB |
correct |
6 |
Correct |
1 ms |
340 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
336 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
332 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
1 ms |
340 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Correct |
1 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
340 KB |
correct |
5 |
Correct |
1 ms |
336 KB |
correct |
6 |
Correct |
1 ms |
340 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
336 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
332 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
1 ms |
340 KB |
correct |
14 |
Correct |
3 ms |
340 KB |
correct |
15 |
Correct |
3 ms |
340 KB |
correct |
16 |
Correct |
3 ms |
340 KB |
correct |
17 |
Correct |
3 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
3 ms |
332 KB |
correct |
20 |
Correct |
2 ms |
340 KB |
correct |
21 |
Correct |
3 ms |
336 KB |
correct |
22 |
Correct |
2 ms |
340 KB |
correct |
23 |
Correct |
2 ms |
340 KB |
correct |
24 |
Correct |
2 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
2 ms |
336 KB |
correct |
27 |
Correct |
2 ms |
340 KB |
correct |
28 |
Correct |
2 ms |
340 KB |
correct |
29 |
Correct |
1 ms |
340 KB |
correct |
30 |
Correct |
2 ms |
336 KB |
correct |
31 |
Correct |
2 ms |
340 KB |
correct |
32 |
Correct |
2 ms |
340 KB |
correct |
33 |
Correct |
2 ms |
332 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Correct |
1 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
340 KB |
correct |
5 |
Correct |
1 ms |
336 KB |
correct |
6 |
Correct |
1 ms |
340 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
336 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
332 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
1 ms |
340 KB |
correct |
14 |
Correct |
3 ms |
340 KB |
correct |
15 |
Correct |
3 ms |
340 KB |
correct |
16 |
Correct |
3 ms |
340 KB |
correct |
17 |
Correct |
3 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
3 ms |
332 KB |
correct |
20 |
Correct |
2 ms |
340 KB |
correct |
21 |
Correct |
3 ms |
336 KB |
correct |
22 |
Correct |
2 ms |
340 KB |
correct |
23 |
Correct |
2 ms |
340 KB |
correct |
24 |
Correct |
2 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
2 ms |
336 KB |
correct |
27 |
Correct |
2 ms |
340 KB |
correct |
28 |
Correct |
2 ms |
340 KB |
correct |
29 |
Correct |
1 ms |
340 KB |
correct |
30 |
Correct |
2 ms |
336 KB |
correct |
31 |
Correct |
2 ms |
340 KB |
correct |
32 |
Correct |
2 ms |
340 KB |
correct |
33 |
Correct |
2 ms |
332 KB |
correct |
34 |
Incorrect |
123 ms |
1560 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Incorrect |
97 ms |
4020 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Correct |
1 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
340 KB |
correct |
5 |
Correct |
1 ms |
336 KB |
correct |
6 |
Correct |
1 ms |
340 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
336 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
332 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
1 ms |
340 KB |
correct |
14 |
Correct |
3 ms |
340 KB |
correct |
15 |
Correct |
3 ms |
340 KB |
correct |
16 |
Correct |
3 ms |
340 KB |
correct |
17 |
Correct |
3 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
3 ms |
332 KB |
correct |
20 |
Correct |
2 ms |
340 KB |
correct |
21 |
Correct |
3 ms |
336 KB |
correct |
22 |
Correct |
2 ms |
340 KB |
correct |
23 |
Correct |
2 ms |
340 KB |
correct |
24 |
Correct |
2 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
2 ms |
336 KB |
correct |
27 |
Correct |
2 ms |
340 KB |
correct |
28 |
Correct |
2 ms |
340 KB |
correct |
29 |
Correct |
1 ms |
340 KB |
correct |
30 |
Correct |
2 ms |
336 KB |
correct |
31 |
Correct |
2 ms |
340 KB |
correct |
32 |
Correct |
2 ms |
340 KB |
correct |
33 |
Correct |
2 ms |
332 KB |
correct |
34 |
Incorrect |
123 ms |
1560 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |