#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 known[nax*nax];
int res[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()) {
int mx = -1, mn = n;
int pos = where[grp[i][0]];
for(int x : grp[i]) {
if(known[x]) continue;
stk[pos] = x;
res[x] = count_common_roads(stk);
//cerr<<x<<'\n';
//cerr<<x<<'\n';
mx = max(mx, res[x]);
mn = min(mn, res[x]);
}
//cerr<<mx<<' '<<mn<<'\n';
if(mx!=mn) {
for(int x : grp[i]) if(!known[x]) {
if(res[x]==mx) known[x] = 2;
else known[x] = 1;
}
} else {
bool something = false;
bool big = false, small = false;
for(int x : grp[i]) if(known[x]) {
something = true;
stk[pos] = x;
if(known[x]==1) {
mn = min(mn, count_common_roads(stk));
small = true;
} else {
mx = max(mx, count_common_roads(stk));
big = true;
}
break;
}
if(something) {
for(int x : grp[i]) if(!known[x]) {
if(res[x]!=mn && small) known[x] = 2;
else if(res[x]!=mx && big) known[x] = 1;
}
} else {
for(int x : grp[i]) {
known[x] = 2;
}
}
}
}
// for(int i=0; i<m; ++i) {
// cerr<<known[i]<<' ';
// }
// cerr<<'\n';
}
for(int i=0; i<m; ++i) if(known[i]==2) {
royal.push_back(i);
//cerr<<i<<' ';
}
//cerr<<'\n';
// for(int x : royal) cerr<<x<<' ';
// cerr<<'\n';
return royal;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Correct |
0 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
340 KB |
correct |
5 |
Correct |
0 ms |
340 KB |
correct |
6 |
Correct |
0 ms |
340 KB |
correct |
7 |
Correct |
1 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
340 KB |
correct |
9 |
Correct |
1 ms |
340 KB |
correct |
10 |
Correct |
0 ms |
340 KB |
correct |
11 |
Correct |
1 ms |
340 KB |
correct |
12 |
Correct |
1 ms |
340 KB |
correct |
13 |
Correct |
1 ms |
340 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Correct |
0 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
340 KB |
correct |
5 |
Correct |
0 ms |
340 KB |
correct |
6 |
Correct |
0 ms |
340 KB |
correct |
7 |
Correct |
1 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
340 KB |
correct |
9 |
Correct |
1 ms |
340 KB |
correct |
10 |
Correct |
0 ms |
340 KB |
correct |
11 |
Correct |
1 ms |
340 KB |
correct |
12 |
Correct |
1 ms |
340 KB |
correct |
13 |
Correct |
1 ms |
340 KB |
correct |
14 |
Correct |
2 ms |
340 KB |
correct |
15 |
Correct |
2 ms |
340 KB |
correct |
16 |
Correct |
3 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 |
3 ms |
340 KB |
correct |
21 |
Correct |
2 ms |
340 KB |
correct |
22 |
Correct |
2 ms |
340 KB |
correct |
23 |
Correct |
2 ms |
340 KB |
correct |
24 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Correct |
0 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
340 KB |
correct |
5 |
Correct |
0 ms |
340 KB |
correct |
6 |
Correct |
0 ms |
340 KB |
correct |
7 |
Correct |
1 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
340 KB |
correct |
9 |
Correct |
1 ms |
340 KB |
correct |
10 |
Correct |
0 ms |
340 KB |
correct |
11 |
Correct |
1 ms |
340 KB |
correct |
12 |
Correct |
1 ms |
340 KB |
correct |
13 |
Correct |
1 ms |
340 KB |
correct |
14 |
Correct |
2 ms |
340 KB |
correct |
15 |
Correct |
2 ms |
340 KB |
correct |
16 |
Correct |
3 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 |
3 ms |
340 KB |
correct |
21 |
Correct |
2 ms |
340 KB |
correct |
22 |
Correct |
2 ms |
340 KB |
correct |
23 |
Correct |
2 ms |
340 KB |
correct |
24 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Incorrect |
102 ms |
4660 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Correct |
0 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
340 KB |
correct |
5 |
Correct |
0 ms |
340 KB |
correct |
6 |
Correct |
0 ms |
340 KB |
correct |
7 |
Correct |
1 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
340 KB |
correct |
9 |
Correct |
1 ms |
340 KB |
correct |
10 |
Correct |
0 ms |
340 KB |
correct |
11 |
Correct |
1 ms |
340 KB |
correct |
12 |
Correct |
1 ms |
340 KB |
correct |
13 |
Correct |
1 ms |
340 KB |
correct |
14 |
Correct |
2 ms |
340 KB |
correct |
15 |
Correct |
2 ms |
340 KB |
correct |
16 |
Correct |
3 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 |
3 ms |
340 KB |
correct |
21 |
Correct |
2 ms |
340 KB |
correct |
22 |
Correct |
2 ms |
340 KB |
correct |
23 |
Correct |
2 ms |
340 KB |
correct |
24 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
25 |
Halted |
0 ms |
0 KB |
- |