编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#81219 #1008. H. 开疆辟土,公司成立 Accepted 100 257 ms 7112 K C++ 11 / 1.1 K Corycle 2022-08-26 16:38:02
显示原始代码
/*====Corycle====*/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 5e5 + 5;
int read() {
    int s = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')
            f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        s = s * 10 + c - '0';
        c = getchar();
    }
    return s * f;
}
int n, m, cnt, Ans, fa[N];
struct edge {
    int x, y, dist;
} e[N];
inline int id(int x, int y) { return (x - 1) * m + y; }
bool cmp(edge A, edge B) { return A.dist > B.dist; }
int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
void Kruskal() {
    sort(e + 1, e + cnt + 1, cmp);
    for (int i = 1; i <= n * m; i++) fa[i] = i;
    for (int i = 1; i <= cnt; i++) {
        int x = Find(e[i].x), y = Find(e[i].y);
        if (x == y)
            continue;
        fa[x] = y;
        Ans -= e[i].dist;
    }
}
int main() {
    //	freopen("_.in","r",stdin);
    //	freopen("_.out","w",stdout);
    int T = read();
    while (T--) {
        n = read();
        m = read();
        cnt = Ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                int x = read(), y = read();
                Ans += x + y;
                if (i != n)
                    e[++cnt] = (edge){ id(i, j), id(i + 1, j), x };
                if (j != m)
                    e[++cnt] = (edge){ id(i, j), id(i, j + 1), y };
            }
        }
        Kruskal();
        printf("%d\n", Ans);
    }
    return 0;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:84 ms
内存:6524 KiB

输入文件(1.in

17
3 3
1 9
7 8
4 0
2 6
12 5
3 0
0 10
0 11
0 0
5 3
10 10
6 5
8 0
9 2
8 1
5 0
5 1
7 
<2829398 bytes omitted>

答案文件(1.ans

10
20
0
7
0
123
163
244
999
1671
100930
181216
80898
1402126
60776271
1014605
19212781

用户输出

10
20
0
7
0
123
163
244
999
1671
100930
181216
80898
1402126
60776271
1014605
19212781

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:54 ms
内存:6504 KiB

输入文件(2.in

1
464 491
795 867
164 87
803 106
734 583
278 855
600 628
824 780
992 364
778 598
747 423

<1999727 bytes omitted>

答案文件(2.ans

60198435

用户输出

60198435

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:58 ms
内存:6528 KiB

输入文件(3.in

1
491 462
33 971
433 904
185 869
103 87
507 127
238 315
994 56
215 73
771 129
430 505
281
<1990927 bytes omitted>

答案文件(3.ans

59997625

用户输出

59997625

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:61 ms
内存:7112 KiB

输入文件(4.in

1
500 500
613 369
811 452
954 965
32 666
60 515
235 679
26 708
45 831
470 788
371 261
101
<2193863 bytes omitted>

答案文件(4.ans

66160818

用户输出

66160818

系统信息

Exited with return code 0