#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);
mx = max(mx, res[x]);
mn = min(mn, res[x]);
}
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;
for(int x : grp[i]) if(known[x]) {
something = true;
stk[pos] = x;
if(known[x]==1) {
mn = min(mn, count_common_roads(stk));
} else {
mx = max(mx, count_common_roads(stk));
}
}
if(something) {
for(int x : grp[i]) if(!known[x]) {
if(res[x]!=mn) known[x] = 2;
else known[x] = 1;
}
} else {
for(int x : grp[i]) {
known[x] = 2;
}
}
}
}
}
for(int i=0; i<m; ++i) if(known[i]==2) {
royal.push_back(i);
}
// for(int x : royal) cerr<<x<<' ';
// cerr<<'\n';
return royal;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Incorrect |
99 ms |
4076 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |