| Task: | Bus lines |
| Sender: | Anonyymit Algoritmistit |
| Submission time: | 2015-09-30 18:47:27 +0300 |
| Language: | Java |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.41 s | details |
| #2 | WRONG ANSWER | 0.61 s | details |
| #3 | RUNTIME ERROR | 0.32 s | details |
| #4 | RUNTIME ERROR | 0.43 s | details |
| #5 | RUNTIME ERROR | 0.35 s | details |
| #6 | RUNTIME ERROR | 0.37 s | details |
| #7 | RUNTIME ERROR | 0.40 s | details |
| #8 | RUNTIME ERROR | 0.40 s | details |
| #9 | WRONG ANSWER | 0.47 s | details |
| #10 | WRONG ANSWER | 0.50 s | details |
| #11 | RUNTIME ERROR | 0.32 s | details |
| #12 | RUNTIME ERROR | 0.40 s | details |
| #13 | RUNTIME ERROR | 0.45 s | details |
| #14 | WRONG ANSWER | 0.77 s | details |
| #15 | WRONG ANSWER | 0.75 s | details |
| #16 | RUNTIME ERROR | 0.46 s | details |
| #17 | WRONG ANSWER | 0.80 s | details |
| #18 | RUNTIME ERROR | 0.42 s | details |
| #19 | WRONG ANSWER | 0.78 s | details |
| #20 | WRONG ANSWER | 0.77 s | details |
| #21 | RUNTIME ERROR | 0.42 s | details |
| #22 | RUNTIME ERROR | 0.43 s | details |
| #23 | RUNTIME ERROR | 0.42 s | details |
| #24 | WRONG ANSWER | 0.72 s | details |
| #25 | RUNTIME ERROR | 0.44 s | details |
Code
//package kilo4;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author asjuvone
*/
public class T3 {
public static int n;
public static int m;
public static int k;
public static Linja[] linjat;
public static Linja[] poistot;
public static int[] isa;
public static int[] koko;
public static int yhdistysCount;
public static void main(String[] args) {
IO io = new IO();
n = io.nextInt();
m = io.nextInt();
k = io.nextInt();
HashMap<Linja, Integer> ekaEsiintyma = new HashMap<>();
HashMap<Linja, Integer> tuplat = new HashMap<>();
linjat = new Linja[m+1];
for (int i=1; i<=m; i++) {
Linja uus = new Linja(io.nextInt(), io.nextInt());
if (tuplat.containsKey(uus)) {
tuplat.put(uus, tuplat.get(uus) + 1);
} else {
tuplat.put(uus, 1);
ekaEsiintyma.put(uus, i);
}
linjat[i] = (uus);
}
ArrayList<Linja> poistot = new ArrayList<>();
for (int i=1; i<=k; i++) {
int kek = io.nextInt();
Linja poisto = linjat[kek];
if (tuplat.get(poisto) > 1) {
tuplat.put(poisto, tuplat.get(poisto)-1);
continue;
}
linjat[kek] = null;
poistot.add(poisto);
}
yhdistysCount = 0;
int[] vastaukset = new int[k+1];
isa = new int[n+1];
koko = new int[n+1];
Arrays.fill(koko, 1);
for (int i=1; i<=n; i++) isa[i] = i;
for (int i=1; i<=m; i++) {
if (linjat[i] == null) continue;
yhdista(linjat[i]);
}
//System.out.println("Region count kaikkien rikkojen jälkeen: " + (n - yhdistysCount));
for (int i=k; i>=1; i--) {
//System.out.println("n: " + n + ", regincount: " + (n-yhdistysCount));
vastaukset[i] = n - yhdistysCount;
yhdista(poistot.get(i-1));
}
//System.out.println(Arrays.toString(vastaukset));
for (int i=1; i<=k; i++) {
System.out.println(vastaukset[i]);
}
io.close();
}
public static void yhdista(Linja uus) {
//System.out.println("Yhdistetään " + uus.a + " ja " + uus.b);
//System.out.println("Isät: " + Arrays.toString(isa));
int a = uus.a;
int b = uus.b;
int rootA = isa[a];
int rootB = isa[b];
while (rootA != isa[a]) {
rootA = isa[a];
}
while (rootB != isa[b]) rootB = isa[b];
if (rootA == rootB) {
return;
}
if (koko[rootA] > koko[rootB]) {
isa[rootB] = rootA;
koko[rootA] += koko[rootB];
} else {
isa[rootA] = rootB;
koko[rootB] += koko[rootA];
}
yhdistysCount++;
}
}
class Linja {
public int a;
public int b;
public Linja(int a, int b) {
this.a = a;
this.b = b;
}
@Override
public boolean equals(Object obj) {
Linja toinen = (Linja) obj;
if (toinen.a == this.b && toinen.b == this.a) return true;
return toinen.a == this.a && toinen.b == this.b;
}
@Override
public int hashCode() {
return a + 36*b;
}
}Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 42712 59669 3327 27393 5935 40762 40800 33005 34639 19131 2850 ... |
| correct output |
|---|
| 2937 2937 2937 2937 2937 2938 ... |
| user output |
|---|
| -16950 -16949 -16948 -16947 -16946 ... |
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 76287 96164 41787 58072 25022 46787 62110 30339 48282 73612 52159 ... |
| correct output |
|---|
| 6969 6969 6969 6969 6970 6970 ... |
| user output |
|---|
| -19868 -19867 -19866 -19865 -19864 ... |
Test 3
Verdict: RUNTIME ERROR
| input |
|---|
| 18336 40887 13506 13131 7525 2330 5108 1053 8852 2934 4194 ... |
| correct output |
|---|
| 208 208 208 208 208 208 208 20... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 13505, Size: 13505 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 4
Verdict: RUNTIME ERROR
| input |
|---|
| 10251 91042 26842 3863 3691 4990 6580 3722 1896 1240 6558 ... |
| correct output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 26841, Size: 26818 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 5
Verdict: RUNTIME ERROR
| input |
|---|
| 75339 65466 44858 37059 62665 14790 65885 12864 58973 70022 19675 ... |
| correct output |
|---|
| 16333 16334 16335 16336 16336 ... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 44857, Size: 44857 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 6
Verdict: RUNTIME ERROR
| input |
|---|
| 2086 66519 52411 361 1822 723 1145 1914 914 2075 1759 ... |
| correct output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 52410, Size: 51899 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 7
Verdict: RUNTIME ERROR
| input |
|---|
| 38126 95132 68427 15424 17170 2781 12706 33834 13802 13405 25848 ... |
| correct output |
|---|
| 246 246 246 246 246 246 246 24... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 68426, Size: 68420 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 8
Verdict: RUNTIME ERROR
| input |
|---|
| 13057 86973 49052 5610 4743 1062 7853 6391 10993 5814 10957 ... |
| correct output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 49051, Size: 49037 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 9
Verdict: WRONG ANSWER
| input |
|---|
| 88876 29498 13976 16610 72903 2735 47496 44512 709 3413 60896 ... |
| correct output |
|---|
| 59380 59381 59382 59383 59384 ... |
| user output |
|---|
| 59379 59380 59381 59382 59383 ... |
Test 10
Verdict: WRONG ANSWER
| input |
|---|
| 54386 40792 30938 11372 35684 36569 35851 24804 11443 2433 7140 ... |
| correct output |
|---|
| 15500 15501 15502 15502 15503 ... |
| user output |
|---|
| 13596 13597 13598 13599 13600 ... |
Test 11
Verdict: RUNTIME ERROR
| input |
|---|
| 18637 33277 33188 6803 17956 14954 12901 7331 13934 15280 6584 ... |
| correct output |
|---|
| 560 560 560 561 561 561 561 56... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 33187, Size: 33186 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 12
Verdict: RUNTIME ERROR
| input |
|---|
| 2637 72943 18160 897 1538 720 703 1919 2314 1803 1644 ... |
| correct output |
|---|
| 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 18159, Size: 17983 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 13
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 100000 100000 87033 99257 40607 9856 32664 94458 61822 19892 ... |
| correct output |
|---|
| 16212 16212 16212 16213 16213 ... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 99999, Size: 99998 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 14
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 100000 4621 68476 54853 81760 28147 87423 33351 48197 ... |
| correct output |
|---|
| 16294 16295 16295 16295 16296 ... |
| user output |
|---|
| 4 5 6 7 8 ... |
Test 15
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 100000 51596 84775 65582 47330 87748 35647 53679 16442 ... |
| correct output |
|---|
| 16120 16121 16122 16122 16123 ... |
| user output |
|---|
| 2 3 4 5 6 ... |
Test 16
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 100000 100000 69292 26196 54314 63616 95 16072 19077 67875 ... |
| correct output |
|---|
| 16149 16149 16149 16149 16150 ... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 99999, Size: 99999 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 17
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 100000 97541 89807 88261 42118 68387 12007 50630 50 ... |
| correct output |
|---|
| 16105 16105 16105 16105 16106 ... |
| user output |
|---|
| 5 6 7 8 9 ... |
Test 18
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 100000 100000 91853 52153 10866 98151 37463 6198 60814 65027 ... |
| correct output |
|---|
| 16154 16155 16155 16155 16156 ... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 99999, Size: 99999 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 19
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 100000 40682 32628 80240 43316 2162 93003 59820 88267 ... |
| correct output |
|---|
| 16398 16398 16398 16398 16398 ... |
| user output |
|---|
| 6 7 8 9 10 ... |
Test 20
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 100000 55437 43499 70984 56856 86259 35090 95150 56215 ... |
| correct output |
|---|
| 16044 16045 16045 16045 16046 ... |
| user output |
|---|
| 6 7 8 9 10 ... |
Test 21
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 100000 100000 4134 98627 66480 41168 90133 75501 94062 11019 ... |
| correct output |
|---|
| 16251 16252 16252 16252 16253 ... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 99999, Size: 99999 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 22
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 100000 100000 6352 451 19430 47543 18870 69498 10423 18161 ... |
| correct output |
|---|
| 16118 16118 16118 16119 16119 ... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 99999, Size: 99999 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 23
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 100000 100000 47553 72232 19034 64055 24491 39922 98399 16192 ... |
| correct output |
|---|
| 16199 16200 16201 16202 16202 ... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 99999, Size: 99999 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
Test 24
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 100000 69140 89073 95544 9460 45106 70799 50772 94371 ... |
| correct output |
|---|
| 16196 16196 16197 16198 16198 ... |
| user output |
|---|
| 3 4 5 6 7 ... |
Test 25
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 100000 100000 22639 28340 10882 29245 74076 54240 87341 51204 ... |
| correct output |
|---|
| 16129 16129 16129 16129 16129 ... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 99999, Size: 99999 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at T3.main(T3.java:82)
