Neterukun's Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Neterukun1993/Library

:heavy_check_mark: 三角形の数え上げ
(Graph/misc/enumerate_triangles.py)

Verified with

Code

def enumerate_triangles(edges, v_vals, MOD):
    n = len(v_vals)
    degs = [0] * n
    for u, v in edges:
        degs[u] += 1
        degs[v] += 1

    graph = [[] for i in range(n)]
    for u, v in edges:
        if v > u:
            u, v = v, u
        if degs[u] > degs[v]:
            u, v = v, u
        graph[u].append(v)

    cnt = 0
    res = 0
    flags = [False] * n

    # v -> nxt_v1, v -> nxt_v2 -> nxtnxt_v について nxt_v1 = nxtnxt_v 
    # 満たす頂点組を数え上げる
    for v in range(n):
        for nxt_v in graph[v]:
            flags[nxt_v] = True
        for nxt_v in graph[v]:
            for nxtnxt_v in graph[nxt_v]:
                if flags[nxtnxt_v]:
                    cnt += 1
                    res += v_vals[v] * v_vals[nxt_v] * v_vals[nxtnxt_v]
                    res %= MOD
        for nxt_v in graph[v]:
            flags[nxt_v] = False

    return cnt, res
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/python.py", line 96, in bundle
    raise NotImplementedError
NotImplementedError
Back to top page