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>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };
#include "meetings.h"
#define kill kool
Vi v[2005];
bool dis[2005][2005];
void discon(int x, int y)
{
dis[x][y]=dis[y][x]=1;
/*
for (int &z : v[x])
{
if (z == y)
{
z = v[x].back();
v[x].back() = y;
}
}
for (int &z : v[y])
{
if (z == x)
{
z = v[y].back();
v[y].back() = x;
}
}
v[x].pop_back();
v[y].pop_back();*/
}
void con(int x, int y)
{
v[x].pb(y);
v[y].pb(x);
}
bool chk[2005], kill[2005];
int sz[2005];
int getSz(int N, int pp)
{
sz[N] = 1;
for (int next : v[N])
{
if (next == pp || kill[next] || dis[N][next])continue;
sz[N] += getSz(next, N);
}
return sz[N];
}
int get_centroid(int N, int pp, int cap)
{
for (int next : v[N])
{
if (kill[next] || next == pp || dis[N][next])continue;
if (sz[next]>cap) return get_centroid(next, N, cap);
}
return N;
}
void Solve(int N)
{
chk[0] = chk[1] = chk[2] = 1;
int w = Query(0, 1, 2);
if (w>2)
{
chk[w] = 1;
con(0, w); con(1, w); con(2, w);
}
else
{
fup(i, 0, 2, 1)if (w != i)con(i, w);
}
fup(i, 3, N - 1, 1)
{
if (chk[i])continue;
chk[i] = 1;
MEM0(kill);
int pr = 0;
while (1)
{
int cap = getSz(pr, -1);
int R = get_centroid(pr, -1, cap / 2);
kill[R] = 1;
Vi w,RR;
fup(j,0,(int)v[R].size()-1,1)if(!dis[i][v[R][j]])RR.pb(v[R][j]);
fup(j, 1, (int)RR.size() - 1, 2)
{
int a = RR[j - 1], b = RR[j];
int x = Query(a, i, b);
if (x == i)
{
int T = Query(R, i, a);
if (T == i)
{
discon(R, a);
con(R, i); con(i, a);
}
else
{
discon(R, b);
con(R, i); con(i, b);
}
goto FIN;
}
else w.pb(x);
}
if (!RR.empty() && RR.size() & 1)
{
int x = Query(R, i, RR.back());
if (x == i)
{
int B = RR.back();
discon(R, RR.back());
con(R, i); con(i, B);
goto FIN;
}
else w.pb(x);
}
int t = -1;
for (int x : w)if (x != R)t = x;
if (t == -1)
{
con(R, i);
goto FIN;
}
else
{
pr = t;
}
}
FIN:;
}
fup(i, 0, N - 1, 1)
{
for (int x : v[i])
{
if (x>i)Bridge(i,x);
}
}
}/*
int main() {
MEM_1(lca);
scanf("%d", &N);
fup(i, 1, N - 1, 1)
{
int x, y;
scanf("%d%d", &x, &y);
vv[x].pb(y);
vv[y].pb(x);
}
dfs(0, 0);
Solve(N);
}*/
# | 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... |