From 72af0dedf9e18911da65b9a5c4906689e868d9fc Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Mon, 8 Jun 2026 17:10:31 +0800 Subject: [legacy] Add functional and performance test suites --- rcc-legacy/tests/functional/18_prim.sy | 75 ++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 rcc-legacy/tests/functional/18_prim.sy (limited to 'rcc-legacy/tests/functional/18_prim.sy') diff --git a/rcc-legacy/tests/functional/18_prim.sy b/rcc-legacy/tests/functional/18_prim.sy new file mode 100644 index 0000000..9a6d246 --- /dev/null +++ b/rcc-legacy/tests/functional/18_prim.sy @@ -0,0 +1,75 @@ +int quick_read(){ + int ch = getch(); int x = 0, f = 0; + while (ch < 48 || ch > 57){ + if (ch == 45) f = 1; + ch = getch(); + } + while (ch >= 48 && ch <=57){ + x = x * 10 + ch - 48; + ch = getch(); + } + if (f) return -x; + else return x; +} +const int maxm = 1005; +const int maxn = 105; +int n, m; +int u[maxm], v[maxm], c[maxm], fa[maxm]; +int find(int x){ + if (x == fa[x]) return x; + int asdf = find(fa[x]); + fa[x] = asdf; + return asdf; +} +int same(int x, int y){ + x = find(x); + y = find(y); + if (x == y) return 1; + return 0; +} +int prim(){ + int i = 0; + while (i < m){ + int j = i + 1; + while (j < m){ + if (c[i] > c[j]){ + int t = u[i]; + u[i] = u[j]; + u[j] = t; + t = v[i]; + v[i] = v[j]; + v[j] = t; + t = c[i]; + c[i] = c[j]; + c[j] = t; + } + j = j + 1; + } + i = i + 1; + } + i = 1; + while (i <= n){ + fa[i] = i; + i = i + 1; + } + i = 0; + int res = 0; + while (i < m){ + if (same(u[i], v[i])) continue; + res = res + c[i]; + fa[find(u[i])]=v[i]; + i = i + 1; + } + return res; +} +int main(){ + int n = quick_read(), m = quick_read(); + int i = 0; + while (i < m){ + u[i] = quick_read(); + v[i] = quick_read(); + c[i] = quick_read(); + i = i + 1; + } + return prim(); +} -- cgit v1.2.3