Submission #27363241
Source Code Expand
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] head = br.readLine().split(" ");
int n = Integer.parseInt(head[0]);
int x = Integer.parseInt(head[1]) - 1;
int[] array = Stream.of(br.readLine().split(" ")).mapToInt(value -> Integer.parseInt(value) - 1)
.toArray();
br.close();
boolean[] isUsed = new boolean[n];
Arrays.fill(isUsed, false);
int ans = 0;
int idx = x;
while (!isUsed[idx]) {
isUsed[idx] = true;
ans += 1;
idx = array[idx];
}
System.out.println(ans);
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Takahashi's Secret |
| User | devgenjin77 |
| Language | Java (OpenJDK 11.0.6) |
| Score | 200 |
| Code Size | 844 Byte |
| Status | AC |
| Exec Time | 220 ms |
| Memory | 47268 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 200 / 200 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 81 ms | 33924 KiB |
| 001.txt | AC | 192 ms | 46552 KiB |
| 002.txt | AC | 194 ms | 46420 KiB |
| 003.txt | AC | 184 ms | 46080 KiB |
| 004.txt | AC | 200 ms | 46432 KiB |
| 005.txt | AC | 197 ms | 46528 KiB |
| 006.txt | AC | 198 ms | 46416 KiB |
| 007.txt | AC | 201 ms | 46732 KiB |
| 008.txt | AC | 210 ms | 47268 KiB |
| 009.txt | AC | 174 ms | 47008 KiB |
| 010.txt | AC | 198 ms | 46536 KiB |
| 011.txt | AC | 185 ms | 46180 KiB |
| 012.txt | AC | 203 ms | 45620 KiB |
| 013.txt | AC | 202 ms | 46576 KiB |
| 014.txt | AC | 192 ms | 46148 KiB |
| 015.txt | AC | 220 ms | 47256 KiB |
| 016.txt | AC | 186 ms | 43984 KiB |
| 017.txt | AC | 171 ms | 41352 KiB |
| 018.txt | AC | 166 ms | 40720 KiB |
| 019.txt | AC | 195 ms | 46728 KiB |
| 020.txt | AC | 200 ms | 46512 KiB |
| 021.txt | AC | 194 ms | 46088 KiB |
| 022.txt | AC | 199 ms | 46364 KiB |
| 023.txt | AC | 194 ms | 46532 KiB |
| example0.txt | AC | 86 ms | 34336 KiB |
| example1.txt | AC | 86 ms | 34264 KiB |