# 【BZOJ2125】最短路（仙人掌，圆方树）

## Code

/**************************************
* Au: Hany01
* Prob: BZOJ2125 最短路（圆方树）
* Date: Jul 30th, 2018
* Email: hany01@foxmail.com
**************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
#define rep(i, j) for (register int i = 0, i##_end_ = j; i < i##_end_; ++ i)
#define For(i, j ,k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define SZ(a) ((int)(a.size()))
#define ALL(a) a.beg1in(), a.end()
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define x first
#define y second
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define y1 wozenmezhemecaia
#ifdef hany01
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

register char c_; register int _, __;
for (_ = 0, __ = 1, c_ = getchar(); !isdigit(c_); c_ = getchar()) if (c_ == '-')  __ = -1;
for ( ; isdigit(c_); c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
return _ * __;
}

const int maxn = 1e4 + 5, maxm = maxn << 2;

int n, e1 = 1, e2 = 1, beg1[maxn], nex1[maxm], v1[maxm], w1[maxm], beg2[maxn << 1], nex2[maxm], v2[maxm], dep[maxn << 1], fa1[maxn], fa2[15][maxn << 1], dfn[maxn], low[maxn], clk, tot;
LL dis1[maxn], dis2[maxn << 1], w2[maxm], cir[maxn];

inline void add1(int uu, int vv, int ww) { v1[++ e1] = vv, w1[e1] = ww, nex1[e1] = beg1[uu], beg1[uu] = e1; }
inline void add2(int uu, int vv, LL ww) { v2[++ e2] = vv, w2[e2] = ww, nex2[e2] = beg2[uu], beg2[uu] = e2; }

inline void Build(int u, int anc, LL dsum) {
static LL d; ++ tot;
for (register int t = u; t != fa1[anc]; t = fa1[t])
cir[t] = dsum, d = min(dis1[t] - dis1[anc], dsum - dis1[t] + dis1[anc]), add2(tot, t, d), add2(t, tot, d);
}

void DFS(int u, int fe) {
dfn[u] = low[u] = ++ clk;
for (register int i = beg1[u]; i; i = nex1[i]) if ((i >> 1) != fe) {
if (!dfn[v1[i]]) dis1[v1[i]] = dis1[u] + w1[i], fa1[v1[i]] = u, DFS(v1[i], i >> 1), chkmin(low[u], low[v1[i]]);
else chkmin(low[u], dfn[v1[i]]);
}
for (register int i = beg1[u]; i; i = nex1[i])
if (fa1[v1[i]] != u && dfn[v1[i]] > dfn[u]) Build(v1[i], u, w1[i] + dis1[v1[i]] - dis1[u]);
}

void DFS(int u) {
for (register int i = beg2[u]; i; i = nex2[i]) if (v2[i] != fa2[0][u])
fa2[0][v2[i]] = u, dis2[v2[i]] = dis2[u] + w2[i], dep[v2[i]] = dep[u] + 1, DFS(v2[i]);
}

inline int LCA(int u, int v) {
if (dep[u] < dep[v]) swap(u, v);
Fordown(i, 14, 0) if (dep[v] + (1 << i) <= dep[u]) u = fa2[i][u];
if (u == v) return u;
Fordown(i, 14, 0) if (fa2[i][u] != fa2[i][v]) u = fa2[i][u], v = fa2[i][v];
return fa2[0][u];
}

inline int climb(int u, int anc) {
Fordown(i, 14, 0) if (dep[fa2[i][u]] > dep[anc]) u = fa2[i][u];
return u;
}

inline LL dist(int u, int v) {
static LL t; t = llabs(dis1[u] - dis1[v]);
assert(cir[u] == cir[v]);
return min(t, cir[u] - t);
}

int main()
{
#ifdef hany01
File("bzoj2125");
#endif

static int m, q, uu, vv, ww, lca, ua, va;

DFS(1, 0), DFS(1);
For(j, 1, 14) For(i, 1, tot) fa2[j][i] = fa2[j - 1][fa2[j - 1][i]];

while (q --) {
}