#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;
using ll = long long;
ll n, m, q, k, x, y, a, b, c;
vector<ll> G[500];
struct dsu {
ll n;
vector<ll> par;
vector<ll> sz;
dsu(ll N) : n(N) {
par.resize(n);
sz.resize(n);
for (int i = 0; i < n; i++) {
par[i] = i;
sz[i] = 1;
}
}
ll find_p(ll x) {
if (par[x] == x) {
return x;
}
ll p = find_p(par[x]);
par[x] = p;
return p;
}
void join(ll x, ll y) {
x = find_p(x);
y = find_p(y);
if (x == y) {
return;
}
if (sz[y] > sz[x]) {
swap(x, y);
}
par[y] = x;
sz[x] += sz[y];
}
};
vector<int> find_roads(int N, vector<int> u, vector<int> v) {
mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
n = N;
m = u.size();
vector< pair< pair<ll, ll>, ll > > vp(m);
for (int i = 0; i < m; i++) {
vp[i].first = {u[i], v[i]};
vp[i].second = i;
G[u[i]].push_back(v[i]);
G[v[i]].push_back(u[i]);
}
map<int, int> ans;
for (int i = 0; i < n; i++) {
// cout << i << endl;
for (int j = 0; j < m; j++) {
swap(vp[j], vp[gen() % (j + 1)]);
}
dsu d(n);
set<ll> st1, st2;
vector<int> e;
for (int j = 0; j < m; j++) {
if (vp[j].first.first == i || vp[j].first.second == i) {
if (ans.count(vp[j].second)) {
st2.insert(vp[j].second);
}
else {
st1.insert(vp[j].second);
}
continue;
}
if (d.find_p(vp[j].first.first) != d.find_p(vp[j].first.second)) {
d.join(vp[j].first.first, vp[j].first.second);
e.push_back(vp[j].second);
}
}
if (st1.size() == 0) {
continue;
}
set<ll> st;
map<ll, ll> to;
for (int j = 0; j < n; j++) {
if (i == j) {
continue;
}
st.insert(d.find_p(j));
}
ll cnt = 0;
for (auto j : st) {
to[j] = cnt++;
}
vector< vector<ll> > v1(cnt), v2(cnt);
for (int j : st1) {
v1[to[d.find_p(v[j] != i ? v[j] : u[j])]].push_back(j);
}
for (int j : st2) {
v2[to[d.find_p(v[j] != i ? v[j] : u[j])]].push_back(j);
}
for (int i = cnt - 1; i >= 0; i--) {
e.push_back((v1[i].size() == 0) ? v2[i][0] : v1[i][0]);
}
reverse(e.begin(), e.end());
// cout << "DEBUG" << endl;
for (int i = 0; i < cnt; i++) {
map< ll, vector<ll> > mp;
for (int j : v1[i]) {
e[i] = j;
mp[count_common_roads(e)].push_back(j);
}
if (mp.size() == 1) {
if (v2[i].size() == 0) {
for (auto j : (*mp.begin()).second) {
ans[j] = 1;
}
}
else {
// cout << "DEBUG" << endl;
e[i] = v2[i][0];
ll x = count_common_roads(e);
for (auto j : mp) {
// cout << '\t' << j.first << ' ' << x << '\n';
for (auto k : j.second) {
// cout << "\t\t" << k << '\t';
if (j.first == x) {
ans[k] = ans[v2[i][0]];
}
else {
ans[k] = 1 - ans[v2[i][0]];
}
// cout << "\t\t" << ans[k] << '\n';
}
}
}
}
else {
for (auto i : (*mp.begin()).second) {
ans[i] = 0;
}
for (auto i : (*++mp.begin()).second) {
ans[i] = 1;
}
}
e[i] = ((v1[i].size() == 0) ? v2[i][0] : v1[i][0]);
}
}
vector<int> ansv;
for (int i = 0; i < m; i++) {
if (ans[i] == 1) {
ansv.push_back(i);
// cout << i << ' ';
}
}
// cout << '\n';
return ansv;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Correct |
0 ms |
348 KB |
correct |
4 |
Correct |
1 ms |
444 KB |
correct |
5 |
Correct |
1 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
452 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Correct |
0 ms |
348 KB |
correct |
4 |
Correct |
1 ms |
444 KB |
correct |
5 |
Correct |
1 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
452 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Correct |
0 ms |
348 KB |
correct |
4 |
Correct |
1 ms |
444 KB |
correct |
5 |
Correct |
1 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
452 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
correct |
2 |
Correct |
1 ms |
344 KB |
correct |
3 |
Incorrect |
93 ms |
6292 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Correct |
0 ms |
348 KB |
correct |
4 |
Correct |
1 ms |
444 KB |
correct |
5 |
Correct |
1 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
452 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |