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>
using namespace std;
using i32 = int;
using i64 = long long;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = V<V<T>>;
template <typename T>
using VVV = V<VV<T>>;
template <typename T>
bool chmin(T &x, const T &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
#define OVERRIDE4(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i)
#define REP3(i, l, r) for (i32 i = (i32)(l); i < (i32)(r); ++i)
#define REP(...) OVERRIDE4(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER2(i, n) for (i32 i = (i32)(n)-1; i >= 0; --i)
#define PER3(i, l, r) for (i32 i = (i32)(r)-1; i >= (i32)(l); --i)
#define PER(...) OVERRIDE4(__VA_ARGS__, PER3, PER2)(__VA_ARGS__)
#define LEN(x) (i32) size(x)
#define ALL(x) begin(x), end(x)
void dbg(i32 x) { cerr << x; }
void dbg(i64 x) { cerr << x; }
template <typename T, typename U>
void dbg(pair<T, U> p) {
cerr << "(";
dbg(p.first);
cerr << ", ";
dbg(p.second);
cerr << ")";
}
template <typename T>
void dbg(V<T> arr) {
cerr << "[";
REP(i, LEN(arr)) {
if (i) {
cerr << ", ";
}
dbg(arr[i]);
}
cerr << "]";
}
void debug() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug(Head head, Tail... tail) {
dbg(head);
cerr << ", ";
debug(tail...);
}
#ifdef DEBUGF
#define DBG(...) \
do { \
cerr << #__VA_ARGS__ << " : "; \
debug(__VA_ARGS__); \
} while (false)
#else
#define DBG(...) (void)0
#endif
#include "simurgh.h"
V<i32> subtask_3(i32 n, V<i32> u, V<i32> v) {
struct Edge {
i32 to, id;
};
i32 m = LEN(u);
VV<Edge> g(n);
REP(i, m) {
g[u[i]].emplace_back(Edge{v[i], i});
g[v[i]].emplace_back(Edge{u[i], i});
}
i32 root = 0;
V<i32> par(n, -1), pid(n, -1), dep(n, -1);
{
queue<i32> que;
que.push(root);
dep[root] = 0;
while (!que.empty()) {
i32 v = que.front();
que.pop();
for (const Edge &e : g[v]) {
if (dep[e.to] == -1) {
par[e.to] = v;
pid[e.to] = e.id;
dep[e.to] = dep[v] + 1;
que.push(e.to);
}
}
}
}
V<i32> tree;
REP(i, n) {
if (pid[i] != -1) {
tree.push_back(pid[i]);
}
}
i32 base = count_common_roads(tree);
V<i32> con(m, -1);
REP(i, m) {
if (count(ALL(tree), i)) {
continue;
}
V<i32> loop;
{
i32 x = u[i], y = v[i];
while (x != y) {
if (dep[x] < dep[y]) {
swap(x, y);
}
loop.push_back(pid[x]);
x = par[x];
}
}
const i32 nil = 998;
V<i32> diffs(LEN(loop), nil);
REP(j, LEN(loop)) {
i32 e = loop[j];
if (con[e] != -1) {
continue;
}
V<i32> ask = tree;
ask.erase(find(ALL(ask), e));
ask.push_back(i);
diffs[j] = count_common_roads(ask) - base;
}
if (auto itr = find(ALL(diffs), nil); itr != end(diffs)) {
{
i32 e = loop[itr - begin(diffs)];
V<i32> ask = tree;
ask.erase(find(ALL(ask), e));
ask.push_back(i);
i32 di = count_common_roads(ask) - base;
con[i] = di + con[e];
}
REP(j, LEN(loop)) {
i32 e = loop[j];
if (con[e] != -1) {
continue;
}
// diffs[j] = con[i] - con[e]
con[e] = con[i] - diffs[j];
}
} else if (count(ALL(diffs), 0) == LEN(diffs)) {
con[i] = 0;
REP(j, LEN(diffs)) { con[loop[j]] = 0; }
} else {
REP(j, LEN(loop)) {
if (diffs[j] == 1) {
con[i] = 1;
}
if (diffs[j] == -1) {
con[i] = 0;
}
}
REP(j, LEN(loop)) {
i32 e = loop[j];
con[e] = con[i] - diffs[j];
}
}
}
REP(i, m) {
if (con[i] == -1) {
con[i] = 1;
}
}
V<i32> ans;
REP(i, m) {
if (con[i] == 1) {
ans.push_back(i);
}
}
return ans;
}
V<i32> find_roads(i32 n, V<i32> u, V<i32> v) {
if (n <= 240) {
return subtask_3(n, u, v);
}
assert(false);
}
# | 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... |