#include "simurgh.h"
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int N = 500 + 10;
vector<pii> G[N], H[N];
int mk[N], E[N], par[N], dep[N];
vector<int> R;
void DFS1(int u, int d = 0){
mk[u] = 1;
dep[u] = d;
for(auto [adj, id] : G[u]){
if(!mk[adj]){
R.pb(id);
par[adj] = u;
DFS1(adj, d + 1);
E[adj] = id;
//cerr << "^ " << u << ' ' << adj << '\n';
}
}
}
ll f;
int mp[N];
int Ask(int rm, int is){
if(mp[rm] != -1) return mp[rm];
vector<int> R2 = R;
for(auto &x : R2) if(x == rm) x = is;
mp[rm] = count_common_roads(R2);
//cerr << "Ask " << rm << ' ' << is << ' ' << mp[{rm, is}] << '\n';
return mp[rm];
}
int sta[N * N];
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
vector<int> r(n - 1);
int m = u.size();
for(int i = 0; i < m; i++){
G[u[i]].pb({v[i], i});
G[v[i]].pb({u[i], i});
}
DFS1(0, 0);
f = count_common_roads(R);
E[0] = -1;
par[0] = -1;
//cerr << "F : " << f << '\n';
vector<int> X;
for(int i = 0; i < m; i++){
if(dep[u[i]] > dep[v[i]]) swap(u[i], v[i]);
if(E[v[i]] == i) continue;
memset(mp, -1, sizeof mp);
X.clear();
int nw = v[i];
////cerr << '\n';
while(nw != u[i]){
////cerr << "# " << nw << '\n';
assert(nw != 0);
X.pb(E[nw]);
nw = par[nw];
}
//cerr << "& " << u[i] << ' ' << v[i] << '\n';
//cerr << "!! ";
//cerr << x << ' ';
//cerr << '\n';
int mn = f;
bool flg = false;
int res;
//cerr << "MTF : " << f << '\n';
for(auto x : X){
if(sta[x] && flg){
if(sta[x] == 2){
mn = min(mn, res);
mp[x] = res;
} else {
mp[x] = res + 1;
mn = min(mn, res + 1);
}
continue;
}
if(sta[x] == 1){
mn = min(mn, Ask(x, i));
res = Ask(x, i) - 1;
flg = true;
} else if(sta[x] == 2){
mn = min(mn, Ask(x, i));
res = Ask(x, i);
flg = true;
} else {
mn = min(mn, Ask(x, i));
}
}
//cerr << "mn : " << mn << '\n';
bool f2 = (f != mn);
for(auto x : X) if(mn != Ask(x, i)) f2 = true;
if(f2){
if(f == mn) sta[i] = 2;
else sta[i] = 1;
for(auto x : X){
if(sta[x] == 0){
if(Ask(x, i) == mn) sta[x] = 2;
else sta[x] = 1;
}
}
} else {
sta[i] = 1;
for(auto x : X) sta[x] = 1;
}
//for(int j = 0; j < m; j++) //cerr << sta[j];
//cerr << '\n';
}
vector<int> res;
for(int i = 0; i < m; i++) if(sta[i] != 1) res.pb(i);
//for(auto x : res)
//cerr << "% " << x << '\n';
assert(((int) res.size()) == n - 1);
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 KB |
correct |
5 |
Correct |
1 ms |
384 KB |
correct |
6 |
Correct |
0 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
1 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
1 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 KB |
correct |
5 |
Correct |
1 ms |
384 KB |
correct |
6 |
Correct |
0 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
1 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
1 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
3 ms |
384 KB |
correct |
15 |
Incorrect |
3 ms |
384 KB |
WA in grader: NO |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 KB |
correct |
5 |
Correct |
1 ms |
384 KB |
correct |
6 |
Correct |
0 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
1 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
1 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
3 ms |
384 KB |
correct |
15 |
Incorrect |
3 ms |
384 KB |
WA in grader: NO |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Runtime error |
30 ms |
6648 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 KB |
correct |
5 |
Correct |
1 ms |
384 KB |
correct |
6 |
Correct |
0 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
1 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
1 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
3 ms |
384 KB |
correct |
15 |
Incorrect |
3 ms |
384 KB |
WA in grader: NO |
16 |
Halted |
0 ms |
0 KB |
- |