用户输出
2
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#69135 | #1257. 车 | Accepted | 100 | 10720 ms | 52896 K | Java / 1.1 K | 新媒体-雷广涵 | 2022-05-01 2:31:44 |
import java.util.HashSet;
import java.util.Scanner;
public class Main {
static HashSet<Integer> hs;
static int m;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
m = in.nextInt();
int n = in.nextInt();
hs = new HashSet<>();
for (int i = 0; i < n; i++) {
hs.add(hash(in.nextInt() - 1, in.nextInt() - 1));
}
int cnt = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if (hs.contains(hash(i, j))) {
dfs(i, j);
cnt++;
}
}
}
System.out.println(n - cnt);
in.close();
}
static int hash(int a, int b) {
return a * 1000 + b;
}
static void dfs(int i, int j) {
hs.remove(hash(i, j));
for (int k = 0; k < m; k++) {
if (hs.contains(hash(i, k))) {
dfs(i, k);
}
}
for (int k = 0; k < 1000; k++) {
if (hs.contains(hash(k, j))) {
dfs(k, j);
}
}
}
}
用户输出
8
系统信息
Exited with return code 0
用户输出
9
系统信息
Exited with return code 0
用户输出
12
系统信息
Exited with return code 0
用户输出
12
系统信息
Exited with return code 0
用户输出
17
系统信息
Exited with return code 0
用户输出
17
系统信息
Exited with return code 0
用户输出
16
系统信息
Exited with return code 0
用户输出
14
系统信息
Exited with return code 0
901 598
565 361
500 175
205 860
524 404
193 20
190 212
379 254
654 653
174 763
344 42
271 140
76 774
<4567 bytes omitted>
用户输出
330
系统信息
Exited with return code 0
530 551
370 236
26 367
405 200
55 355
436 316
478 344
397 315
476 392
60 512
233 526
514 248
429 325
<4086 bytes omitted>
用户输出
396
系统信息
Exited with return code 0
904 84
121 471
711 121
862 151
441 193
514 539
479 427
342 129
583 269
260 175
607 462
641 578
282 2
<560 bytes omitted>
用户输出
2
系统信息
Exited with return code 0
322 197
178 243
39 189
83 306
293 89
254 60
223 82
96 176
262 302
276 15
135 248
265 232
63 281
179
<1356 bytes omitted>
用户输出
91
系统信息
Exited with return code 0
569 804
264 153
179 489
204 404
121 227
309 101
534 470
361 276
537 107
474 107
513 334
167 332
313
<6023 bytes omitted>
用户输出
729
系统信息
Exited with return code 0
254 526
54 106
142 201
49 219
238 117
136 242
171 196
132 49
59 44
195 169
103 230
222 77
154 159
14
<3680 bytes omitted>
用户输出
511
系统信息
Exited with return code 0
300 844
197 204
168 265
277 270
101 251
192 36
222 79
270 212
242 139
161 124
169 220
182 249
177 25
<6051 bytes omitted>
用户输出
839
系统信息
Exited with return code 0
503 668
81 343
481 83
182 390
22 300
487 210
278 503
164 337
90 1
437 244
219 20
98 97
210 262
76 42
<5008 bytes omitted>
用户输出
577
系统信息
Exited with return code 0
300 848
273 182
240 132
279 174
237 281
279 180
131 34
24 238
239 8
274 237
63 24
79 233
204 105
75
<6055 bytes omitted>
用户输出
841
系统信息
Exited with return code 0
166 728
126 14
151 109
118 126
112 37
76 151
6 71
98 94
117 79
101 90
84 42
117 112
42 7
54 6
155 98
<4795 bytes omitted>
用户输出
727
系统信息
Exited with return code 0
7 49
1 1
1 2
1 3
1 4
1 5
1 6
1 7
2 1
2 2
2 3
2 4
2 5
2 6
2 7
3 1
3 2
3 3
3 4
3 5
3 6
3 7
4 1
4 2
4 3
<101 bytes omitted>
用户输出
48
系统信息
Exited with return code 0
15 225
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
2 1
2 2
2 3
2 4
2 5
2 6
2 7
<987 bytes omitted>
用户输出
224
系统信息
Exited with return code 0
26 676
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1
<3495 bytes omitted>
用户输出
675
系统信息
Exited with return code 0
31 961
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1
<5115 bytes omitted>
用户输出
960
系统信息
Exited with return code 0
666 999
1 1
1 2
2 2
4 3
3 4
4 4
5 5
6 5
6 6
7 7
8 7
7 8
9 9
9 10
10 10
12 11
11 12
12 12
13 13
14 13
<7576 bytes omitted>
用户输出
666
系统信息
Exited with return code 0
666 999
2 1
1 2
2 2
4 3
3 4
4 4
5 5
6 5
6 6
8 7
7 8
8 8
9 9
10 9
9 10
12 11
11 12
12 12
13 13
14 13
<7576 bytes omitted>
用户输出
666
系统信息
Exited with return code 0
666 999
2 1
1 2
2 2
3 3
4 3
4 4
6 5
5 6
6 6
7 7
7 8
8 8
9 9
10 9
10 10
11 11
11 12
12 12
13 13
14 13
<7576 bytes omitted>
用户输出
666
系统信息
Exited with return code 0
666 999
2 1
1 2
2 2
3 3
4 3
3 4
5 5
6 5
5 6
8 7
7 8
8 8
9 9
10 9
10 10
11 11
11 12
12 12
13 13
14 13
<7575 bytes omitted>
用户输出
666
系统信息
Exited with return code 0
666 999
2 1
1 2
2 2
3 3
3 4
4 4
5 5
6 5
6 6
7 7
7 8
8 8
9 9
10 9
10 10
11 11
11 12
12 12
13 13
14 13
<7576 bytes omitted>
用户输出
666
系统信息
Exited with return code 0
666 999
1 1
1 2
2 2
3 3
4 3
4 4
5 5
5 6
6 6
7 7
8 7
8 8
9 9
10 9
9 10
11 11
11 12
12 12
14 13
13 14
<7575 bytes omitted>
用户输出
666
系统信息
Exited with return code 0
666 999
1 1
2 1
2 2
3 3
3 4
4 4
6 5
5 6
6 6
7 7
8 7
8 8
9 9
10 9
10 10
11 11
12 11
12 12
13 13
14 13
<7577 bytes omitted>
用户输出
666
系统信息
Exited with return code 0
666 999
1 1
2 1
1 2
3 3
4 3
3 4
5 5
5 6
6 6
7 7
7 8
8 8
9 9
10 9
10 10
11 11
12 11
11 12
13 13
13 14
<7575 bytes omitted>
用户输出
666
系统信息
Exited with return code 0
666 999
2 1
1 2
2 2
3 3
4 3
3 4
5 5
5 6
6 6
8 7
7 8
8 8
9 9
10 9
10 10
11 11
12 11
12 12
13 13
14 13
<7576 bytes omitted>
用户输出
666
系统信息
Exited with return code 0
666 999
2 1
1 2
2 2
3 3
4 3
3 4
5 5
6 5
5 6
7 7
8 7
7 8
9 9
10 9
9 10
12 11
11 12
12 12
13 13
13 14
<7575 bytes omitted>
用户输出
666
系统信息
Exited with return code 0
用户输出
9
系统信息
Exited with return code 0
用户输出
9
系统信息
Exited with return code 0
100 100
1 55
2 55
3 55
4 55
5 55
6 55
7 55
8 55
9 55
10 55
11 55
12 55
13 55
14 55
15 55
16 55
17 55
<500 bytes omitted>
用户输出
99
系统信息
Exited with return code 0
100 100
81 1
81 2
81 3
81 4
81 5
81 6
81 7
81 8
81 9
81 10
81 11
81 12
81 13
81 14
81 15
81 16
81 17
<500 bytes omitted>
用户输出
99
系统信息
Exited with return code 0
1000 1000
1 608
2 608
3 608
4 608
5 608
6 608
7 608
8 608
9 608
10 608
11 608
12 608
13 608
14 608
1
<7803 bytes omitted>
用户输出
999
系统信息
Exited with return code 0