---
id: 1955
lang: en
translation_of: index.md
source_sha256: 30479ed2bb7982168b49ee0a1fa81858552492dafedb75890229690ee4aa3079
title: "[Fortuna OJ] Jan 10 Provincial Selection Division – Problem-Solving Report"
description: "At Jizhong, if you don't put up your mosquito net properly, just wait for the next day's contest to go GG."
tags: ["OI","Hashing","Tarjan","Computational Geometry","Straddle Test","Tree Hashing"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "Problem names 鸡腿の梦境 / 花园 / 游戏 rendered as Drumstick's Dreamland / Garden / Game: 鸡腿 (“chicken drumstick”) reads as a character name, and the Japanese-style の as a plain possessive."
  - "The ' - ' in the title rendered as an en dash to match the sibling Fortuna OJ translations (1950, 1960); the problem headings keep the hyphen as stored."
  - "缩点 (contracting components) rendered as “condensation”."
  - "Description translates the Chinese meta description, which is the post's epigraph."
---

> At Jizhong, if you don't put up your mosquito net properly, just wait for the next day's contest to go <span class="slang" data-zh="GG" data-gloss="Gamer shorthand for “good game”, typed when conceding a match. Here: it is over, I am done for.">GG</span>.
>
> kal0rona

<!--more-->

## A - Drumstick's Dreamland

A computational geometry <span class="slang" data-zh="套路" data-gloss="tàolù, “routine, set pattern”. OI slang for a standard, well-known trick that works on a whole class of problems.">standard-trick</span> problem, so I don't know how to do it.

Actually, during the contest I could tell it was about checking whether a point lies inside a polygon, but I really didn't know how to write it, and so I <span class="slang" data-zh="爆零" data-gloss="bàolíng, “explode to zero”. Scoring zero points on a problem or contest.">scored zero</span>. The main principle lies in the straddle test and detecting odd-weight cycles.

```cpp
// A.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 330;

int n, head[MAX_N], current;
double ri[MAX_N];
bool vis[MAX_N][2];

struct edge
{
    int to, nxt, weight;
} edges[MAX_N * MAX_N << 1];

void addpath(int src, int dst, int weight)
{
    edges[current].to = dst, edges[current].nxt = head[src];
    edges[current].weight = weight, head[src] = current++;
}

struct point
{
    double x, y;
} pts[MAX_N];

double pow2(double x) { return x * x; }

double getDist(point &a, point &b) { return sqrt(pow2(a.x - b.x) + pow2(a.y - b.y)); }

bool judge(point &a, point &b, point &c, point &d)
{
    double u, v, w, z;
    u = (c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y);
    v = (d.x - a.x) * (b.y - a.y) - (b.x - a.x) * (d.y - a.y);
    w = (a.x - c.x) * (d.y - c.y) - (d.x - c.x) * (a.y - c.y);
    z = (b.x - c.x) * (d.y - c.y) - (d.x - c.x) * (b.y - c.y);
    return (u * v <= 0.00001 && w * z <= 0.00001);
}

void dfs(int u, int fa, int opt)
{
    if (vis[u][opt])
        return;
    vis[u][opt] = true;
    for (int i = head[u]; i != -1; i = edges[i].nxt)
        if (edges[i].to != fa)
            dfs(edges[i].to, u, opt ^ edges[i].weight);
}

int main()
{
    point remote_point = {9024.0, 6002.0};
    while (scanf("%d", &n) != EOF)
    {
        memset(head, -1, sizeof(head)), current = 0;
        for (int i = 1; i <= n + 1; i++)
            scanf("%lf%lf%lf", &pts[i].x, &pts[i].y, &ri[i]);
        for (int i = 1; i <= n; i++)
            ri[i] += ri[n + 1];
        for (int i = 1; i <= n; i++)
            for (int j = i + 1; j <= n; j++)
                if (getDist(pts[i], pts[j]) < ri[i] + ri[j])
                    if (judge(pts[i], pts[j], pts[n + 1], remote_point))
                        addpath(i, j, 1), addpath(j, i, 1);
                    else
                        addpath(i, j, 0), addpath(j, i, 0);
        bool flag = true;
        for (int i = 1; i <= n; i++)
        {
            memset(vis, false, sizeof(vis));
            dfs(i, 0, 0);
            for (int j = 1; j <= n; j++)
                if (vis[j][0] && vis[j][1])
                {
                    flag = false;
                    break;
                }
            if (flag == false)
                break;
        }
        puts(flag ? "YES" : "NO");
    }
    return 0;
}
```

## B - Drumstick's Garden

I hate <span class="slang" data-zh="卡哈希" data-gloss="kǎ hāxī, “jam the hash”. Test data deliberately built to make hashing solutions collide and fail.">anti-hash data</span>. Made the hash function a bit weirder and the <span class="slang" data-zh="特么" data-gloss="tème, a euphemistic spelling of 他妈 (tāmā), “his mother”. A mild curse, like “damn” or “freaking”.">damn</span> thing passed, <span class="slang" data-zh="害" data-gloss="hài, “harm”, used online in place of the sigh 唉 or 嗨. A resigned sigh, roughly “oh well”.">sigh</span>.

```cpp
// B.cpp
#include <bits/stdc++.h>
#define ull unsigned long long

using namespace std;

const int MAX_N = 2e5 + 200, bitnum = 133, mod1 = 1e9 + 7, mod2 = 1e9 + 9, bitlft = 23333, bitrig = 998443;

struct hash_val
{
    int val1, val2;

    hash_val operator+(const int &ch)
    {
        hash_val ret = *this;
        ret.val1 = (1LL * ret.val1 + mod1 + ch) % mod1;
        ret.val2 = (1LL * ret.val2 + mod2 + ch) % mod2;
        return ret;
    }

    hash_val operator+(const hash_val &ch)
    {
        hash_val ret = *this;
        ret.val1 = (1LL * ret.val1 + mod1 + ch.val1) % mod1;
        ret.val2 = (1LL * ret.val2 + mod2 + ch.val2) % mod2;
        return ret;
    }

    hash_val operator-(const hash_val &rhs)
    {
        hash_val ret = *this;
        ret.val1 = (0LL + ret.val1 + mod1 - rhs.val1) % mod1;
        ret.val2 = (0LL + ret.val2 + mod2 - rhs.val2) % mod2;
        return ret;
    }

    hash_val operator*(const int &rhs)
    {
        hash_val ret = *this;
        ret.val1 = 1LL * ret.val1 * rhs % mod1;
        ret.val2 = 1LL * ret.val2 * rhs % mod2;
        return ret;
    }

    hash_val operator*(const hash_val &rhs)
    {
        hash_val ret = *this;
        ret.val1 = 1LL * ret.val1 * rhs.val1 % mod1;
        ret.val2 = 1LL * ret.val2 * rhs.val2 % mod2;
        return ret;
    }

    bool operator==(const hash_val &target) const { return val1 == target.val1 && val2 == target.val2; }

    bool operator<(const hash_val &target) const { return val1 < target.val1 || (val1 == target.val1 && val2 < target.val2); }
};

int n, m, ch[MAX_N][2], siz[MAX_N], fa[MAX_N];
hash_val nodes[MAX_N], bpow[MAX_N];
map<hash_val, int> mp;
long long ans = 0;

void dfs(int u, int opt)
{
    siz[u] = 1;
    if (ch[u][0] != -1)
        dfs(ch[u][0], opt), siz[u] += siz[ch[u][0]];
    else
        ch[u][0] = 0;
    if (ch[u][1] != -1)
        dfs(ch[u][1], opt), siz[u] += siz[ch[u][1]];
    else
        ch[u][1] = 0;

    hash_val curt = hash_val{0, 0};
    curt = nodes[ch[u][0]] * nodes[ch[u][0]] * bitlft + nodes[ch[u][1]] * bitrig + (siz[u] ^ siz[ch[u][1]]);
    nodes[u] = curt;
    if (opt == 0)
        mp[nodes[u]]++;
    else
        ans += mp[nodes[u]];
}

void setFather(int x, int fat) { x > 0 ? fa[x] = fat : 0; }

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%d%d", &ch[i][0], &ch[i][1]), setFather(ch[i][0], i), setFather(ch[i][1], i);
    bpow[0] = hash_val{1, 1};
    for (int i = 1; i <= max(n, m); i++)
        bpow[i] = bpow[i - 1] * bitnum;
    for (int i = n + 1; i <= n + m; i++)
    {
        scanf("%d%d", &ch[i][0], &ch[i][1]);
        if (ch[i][0] != -1)
            ch[i][0] += n;
        if (ch[i][1] != -1)
            ch[i][1] += n;
        setFather(ch[i][0], i), setFather(ch[i][1], i);
    }
    int root1, root2;
    for (int i = 1; i <= n; i++)
        if (fa[i] == 0)
            root1 = i;
    for (int i = n + 1; i <= n + m; i++)
        if (fa[i] == 0)
            root2 = i;
    dfs(root1, 0), dfs(root2, 1), printf("%lld\n", ans);
    return 0;
}
```

## C - Drumstick's Game

I must have been <span class="slang" data-zh="特么" data-gloss="tème, a euphemistic spelling of 他妈 (tāmā), “his mother”. A mild curse, like “damn” or “freaking”.">damn</span> possessed: I kept writing condensation, and in the end found that it is a lot like BLO.

First, write a Tarjan following the <span class="slang" data-zh="套路" data-gloss="tàolù, “routine, set pattern”. OI slang for a standard, well-known trick that works on a whole class of problems.">standard trick</span> for articulation points. When the vertex is an articulation point, we need to count the vertex pairs whose LCA in the search tree is $u$. It is pretty much the same as BLO (doubtful), and then it is solved (I really am <span class="slang" data-zh="sb" data-gloss="Initials of 傻逼 (shǎbī). A vulgar insult, roughly “idiot” or “stupid”.">stupid</span>).

```cpp
// C.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 5e4 + 200, MAX_E = 1e5 + 200;
typedef long long ll;

int head[MAX_N], current, n, m, dfn[MAX_N], low[MAX_N], ptot, tot[MAX_N];
ll ans[MAX_N];

struct edge
{
    int to, nxt;
} edges[MAX_E << 1];

void addpath(int src, int dst)
{
    edges[current].to = dst, edges[current].nxt = head[src];
    head[src] = current++;
}

void tarjan(int u, int fa)
{
    ll cnt = 0;
    dfn[u] = low[u] = ++ptot;
    for (int i = head[u]; i != -1; i = edges[i].nxt)
        if (edges[i].to != fa)
            if (dfn[edges[i].to] == 0)
            {
                tarjan(edges[i].to, u), low[u] = min(low[u], low[edges[i].to]);
                tot[u] += tot[edges[i].to];
                if (low[edges[i].to] >= dfn[u])
                {
                    ans[u] -= cnt * tot[edges[i].to], ans[u] += 1LL * (n - tot[edges[i].to] - 1) * tot[edges[i].to];
                    cnt += tot[edges[i].to];
                }
            }
            else
                low[u] = min(low[u], dfn[edges[i].to]);
    ans[u] += n - 1, tot[u]++;
}

int main()
{
    memset(head, -1, sizeof(head));
    scanf("%d%d", &n, &m);
    for (int i = 1, u, v; i <= m; i++)
    {
        scanf("%d%d", &u, &v);
        if (u != v)
            addpath(u, v), addpath(v, u);
    }
    for (int i = 1; i <= n; i++)
        if (dfn[i] == 0)
            tarjan(i, 0);
    for (int i = 1; i <= n; i++)
        printf("%lld\n", ans[i]);
    return 0;
}
```
