| Task: | Bus lines |
| Sender: | Anonyymit Algoritmistit |
| Submission time: | 2015-09-30 19:34:41 +0300 |
| Language: | Java |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.32 s | details |
| #2 | WRONG ANSWER | 0.47 s | details |
| #3 | WRONG ANSWER | 0.38 s | details |
| #4 | WRONG ANSWER | 0.42 s | details |
| #5 | WRONG ANSWER | 0.47 s | details |
| #6 | WRONG ANSWER | 0.48 s | details |
| #7 | WRONG ANSWER | 0.68 s | details |
| #8 | WRONG ANSWER | 0.54 s | details |
| #9 | WRONG ANSWER | 0.40 s | details |
| #10 | WRONG ANSWER | 0.42 s | details |
| #11 | WRONG ANSWER | 0.46 s | details |
| #12 | WRONG ANSWER | 0.40 s | details |
| #13 | WRONG ANSWER | 0.64 s | details |
| #14 | WRONG ANSWER | 0.64 s | details |
| #15 | WRONG ANSWER | 0.65 s | details |
| #16 | WRONG ANSWER | 0.61 s | details |
| #17 | WRONG ANSWER | 0.76 s | details |
| #18 | WRONG ANSWER | 0.64 s | details |
| #19 | WRONG ANSWER | 0.64 s | details |
| #20 | WRONG ANSWER | 0.66 s | details |
| #21 | WRONG ANSWER | 0.62 s | details |
| #22 | WRONG ANSWER | 0.61 s | details |
| #23 | WRONG ANSWER | 0.65 s | details |
| #24 | WRONG ANSWER | 0.61 s | details |
| #25 | WRONG ANSWER | 0.61 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());
linjat[i] = (uus);
}
ArrayList<Linja> poistot = new ArrayList<>();
for (int i=1; i<=k; i++) {
int kek = io.nextInt();
Linja poisto = linjat[kek];
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;
if (poistot.get(i-1).a > 0) 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) {
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[rootB]) rootB = isa[rootB];
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 |
|---|
| -13788 -13787 -13786 -13786 -13785 ... |
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 |
|---|
| -16290 -16289 -16288 -16288 -16287 ... |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 18336 40887 13506 13131 7525 2330 5108 1053 8852 2934 4194 ... |
| correct output |
|---|
| 208 208 208 208 208 208 208 20... |
| user output |
|---|
| -16861 -16860 -16859 -16858 -16857 ... |
Test 4
Verdict: WRONG ANSWER
| 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 |
|---|
| -53190 -53189 -53189 -53189 -53188 ... |
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 75339 65466 44858 37059 62665 14790 65885 12864 58973 70022 19675 ... |
| correct output |
|---|
| 16333 16334 16335 16336 16336 ... |
| user output |
|---|
| 10032 10033 10034 10035 10036 ... |
Test 6
Verdict: WRONG ANSWER
| 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 |
|---|
| -41283 -41283 -41283 -41282 -41281 ... |
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 38126 95132 68427 15424 17170 2781 12706 33834 13802 13405 25848 ... |
| correct output |
|---|
| 246 246 246 246 246 246 246 24... |
| user output |
|---|
| -42205 -42204 -42203 -42202 -42201 ... |
Test 8
Verdict: WRONG ANSWER
| 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 |
|---|
| -48930 -48930 -48930 -48930 -48929 ... |
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 |
|---|
| 13600 13601 13602 13603 13604 ... |
Test 11
Verdict: WRONG ANSWER
| input |
|---|
| 18637 33277 33188 6803 17956 14954 12901 7331 13934 15280 6584 ... |
| correct output |
|---|
| 560 560 560 561 561 561 561 56... |
| user output |
|---|
| -11230 -11230 -11230 -11229 -11228 ... |
Test 12
Verdict: WRONG ANSWER
| 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 |
|---|
| -44928 -44927 -44926 -44926 -44926 ... |
Test 13
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 100000 87033 99257 40607 9856 32664 94458 61822 19892 ... |
| correct output |
|---|
| 16212 16212 16212 16213 16213 ... |
| user output |
|---|
| 1093 1094 1095 1096 1097 ... |
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 |
|---|
| 1005 1006 1006 1007 1008 ... |
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 |
|---|
| 1077 1078 1079 1080 1081 ... |
Test 16
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 100000 69292 26196 54314 63616 95 16072 19077 67875 ... |
| correct output |
|---|
| 16149 16149 16149 16149 16150 ... |
| user output |
|---|
| 1070 1071 1071 1072 1073 ... |
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 |
|---|
| 1162 1163 1164 1165 1166 ... |
Test 18
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 100000 91853 52153 10866 98151 37463 6198 60814 65027 ... |
| correct output |
|---|
| 16154 16155 16155 16155 16156 ... |
| user output |
|---|
| 1115 1116 1117 1118 1119 ... |
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 |
|---|
| 1240 1240 1241 1242 1242 ... |
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 |
|---|
| 1082 1083 1084 1084 1085 ... |
Test 21
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 100000 4134 98627 66480 41168 90133 75501 94062 11019 ... |
| correct output |
|---|
| 16251 16252 16252 16252 16253 ... |
| user output |
|---|
| 1096 1097 1098 1099 1100 ... |
Test 22
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 100000 6352 451 19430 47543 18870 69498 10423 18161 ... |
| correct output |
|---|
| 16118 16118 16118 16119 16119 ... |
| user output |
|---|
| 1057 1058 1059 1060 1061 ... |
Test 23
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 100000 47553 72232 19034 64055 24491 39922 98399 16192 ... |
| correct output |
|---|
| 16199 16200 16201 16202 16202 ... |
| user output |
|---|
| 1059 1060 1061 1062 1063 ... |
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 |
|---|
| 1102 1103 1104 1105 1106 ... |
Test 25
Verdict: WRONG ANSWER
| input |
|---|
| 100000 100000 100000 22639 28340 10882 29245 74076 54240 87341 51204 ... |
| correct output |
|---|
| 16129 16129 16129 16129 16129 ... |
| user output |
|---|
| 1072 1073 1073 1073 1074 ... |
