Skip to content

Commit 2dfc27e

Browse files
committed
modify code
1 parent e951e9a commit 2dfc27e

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed
Binary file not shown.

src/class164/Code02_Training1.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
// youyou的军训,java版
44
// 图里有n个点,m条无向边,每条边给定不同的边权,图里可能有若干个连通的部分
5-
// 一开始limit = 0,接下来有q条操作,每条操作都是如下的三种类型中的一种
6-
// 操作 1 x : 所有修改操作生效,然后limit变成x,图中那些边权小于limit的边断开
7-
// 操作 2 x : 查询点x所在连通区域大小
8-
// 操作 3 x y : 第x条边的边权修改为y,但不是立刻生效,而是下次limit改变时生效
9-
// 题目保证边权不管怎么修改,所有边权都不相等,并且每条边的边权排名不发生变化
5+
// 一开始limit = 0,接下来有q条操作,每种操作的格式如下
6+
// 操作 1 x : 所有修改操作生效,然后limit设置成x
7+
// 操作 2 x : 从点x出发,只能走过 边权 < limit 的边,查询最多到达几个点
8+
// 操作 3 x y : 第x条边的边权修改为y,不是立刻生效,等到下次操作1发生时生效
9+
// 题目保证边权不管如何修改,所有边权都不相等,并且每条边的边权排名不发生变化
1010
// 1 <= n、m、q <= 4 * 10^5
1111
// 测试链接 : https://www.luogu.com.cn/problem/P9638
1212
// 提交以下的code,提交时请把类名改成"Main",可以通过所有测试用例
@@ -28,6 +28,14 @@ public class Code02_Training1 {
2828
// 边的编号对应重构树上的点的编号
2929
public static int[] edgeToTree = new int[MAXM];
3030

31+
// 边权的修改操作先不生效,等到下次操作1发生时生效
32+
// 修改了哪些边
33+
public static int[] pendEdge = new int[MAXM];
34+
// 修改成了什么边权
35+
public static int[] pendVal = new int[MAXM];
36+
// 修改操作的个数
37+
public static int cntp = 0;
38+
3139
// 并查集
3240
public static int[] father = new int[MAXK];
3341
public static int[] stack = new int[MAXK];
@@ -45,14 +53,6 @@ public class Code02_Training1 {
4553
// 树上dfs,Kruskal重构树的节点,倍增表
4654
public static int[][] stjump = new int[MAXK][MAXH];
4755

48-
// 边权的修改操作先不生效,等到下次limit被设置时生效
49-
// 修改了哪些边
50-
public static int[] pendEdge = new int[MAXM];
51-
// 修改成了什么边权
52-
public static int[] pendVal = new int[MAXM];
53-
// 修改操作的个数
54-
public static int cntp = 0;
55-
5656
// 并查集的find方法,需要改成迭代版不然会爆栈,C++实现不需要
5757
public static int find(int i) {
5858
int size = 0;
@@ -190,7 +190,7 @@ public static void main(String[] args) {
190190
for (int i = 1; i <= q; i++) {
191191
op = io.nextInt();
192192
if (op == 1) {
193-
// 从上次limit改变开始,积攒的修改操作统一生效
193+
// 收集的修改操作生效
194194
for (int k = 1; k <= cntp; k++) {
195195
nodeKey[edgeToTree[pendEdge[k]]] = pendVal[k];
196196
}
@@ -202,7 +202,7 @@ public static void main(String[] args) {
202202
} else {
203203
x = io.nextInt();
204204
y = io.nextInt();
205-
// 修改操作先收集起来,等到limit改变时,统一生效
205+
// 收集修改操作
206206
if (edgeToTree[x] != 0) {
207207
pendEdge[++cntp] = x;
208208
pendVal[cntp] = y;

src/class164/Code02_Training2.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
// youyou的军训,C++版
44
// 图里有n个点,m条无向边,每条边给定不同的边权,图里可能有若干个连通的部分
5-
// 一开始limit = 0,接下来有q条操作,每条操作都是如下的三种类型中的一种
6-
// 操作 1 x : 所有修改操作生效,然后limit变成x,图中那些边权小于limit的边断开
7-
// 操作 2 x : 查询点x所在连通区域大小
8-
// 操作 3 x y : 第x条边的边权修改为y,但不是立刻生效,而是下次limit改变时生效
9-
// 题目保证边权不管怎么修改,所有边权都不相等,并且每条边的边权排名不发生变化
5+
// 一开始limit = 0,接下来有q条操作,每种操作的格式如下
6+
// 操作 1 x : 所有修改操作生效,然后limit设置成x
7+
// 操作 2 x : 从点x出发,只能走过 边权 < limit 的边,查询最多到达几个点
8+
// 操作 3 x y : 第x条边的边权修改为y,不是立刻生效,等到下次操作1发生时生效
9+
// 题目保证边权不管如何修改,所有边权都不相等,并且每条边的边权排名不发生变化
1010
// 1 <= n、m、q <= 4 * 10^5
1111
// 测试链接 : https://www.luogu.com.cn/problem/P9638
1212
// 如下实现是C++的版本,C++版本和java版本逻辑完全一样
@@ -28,9 +28,14 @@
2828
//const int MAXM = 400001;
2929
//const int MAXH = 20;
3030
//int n, m, q;
31+
//
3132
//Edge edge[MAXM];
3233
//int edgeToTree[MAXM];
3334
//
35+
//int pendEdge[MAXM];
36+
//int pendVal[MAXM];
37+
//int cntp;
38+
//
3439
//int father[MAXK];
3540
//
3641
//int head[MAXK];
@@ -43,10 +48,6 @@
4348
//int leafsiz[MAXK];
4449
//int stjump[MAXK][MAXH];
4550
//
46-
//int pendEdge[MAXM];
47-
//int pendVal[MAXM];
48-
//int cntp;
49-
//
5051
//int find(int i) {
5152
// if (i != father[i]) {
5253
// father[i] = find(father[i]);

0 commit comments

Comments
 (0)