ABC 303

https://atcoder.jp/contests/abc303

A. Similar String

https://atcoder.jp/contests/abc303/tasks/abc303_a

B. Discord

https://atcoder.jp/contests/abc303/tasks/abc303_b

C. Dash

https://atcoder.jp/contests/abc303/tasks/abc303_c

D. Shift vs. CapsLock

https://atcoder.jp/contests/abc303/tasks/abc303_d

E. A Gift From the Stars

https://atcoder.jp/contests/abc303/tasks/abc303_e

葉から始めて距離が3離れたノードは別の star graph の葉に相当する。また葉の隣のノードは star graph の中心。 これよりある葉から出発して $3i+1$ 離れたノードは star graph の中心だったものである。 これより中心の頂点番号が取れるのでそのノードにおける次数を昇順に出力すればよい。

void solve() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vvint graph(n);
    rep(i, n - 1) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    vint sz;

    auto dfs = [&](auto dfs, int now, int p, int label) -> void {
        if (label == 1) {
            sz.push_back(graph[now].size());
        }

        for (int nx : graph[now]) {
            if (nx == p)
                continue;
            dfs(dfs, nx, now, (label + 1) % 3);
        }
    };

    rep(i, n) if (graph[i].size() == 1) {
        dfs(dfs, i, -1, 0);
        break;
    }

    sort(all(sz));
    print(sz);
}

F. Damage over Time

https://atcoder.jp/contests/abc303/tasks/abc303_f

G. Bags Game

https://atcoder.jp/contests/abc303/tasks/abc303_g

Ex. Constrained Tree Degree

https://atcoder.jp/contests/abc303/tasks/abc303_h