This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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(big && mx!=mn) small = true;
if(small && mx!=mn) big = true;
if(something) {
for(int x : grp[i]) if(!known[x]) {
if(res[x]==mn && small) known[x] = 1;
else if(res[x]==mx && big) known[x] = 2;
else {
cerr<<mx<<' '<<mn<<' '<<res[x]<<'\n';
}
}
} 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |