Contest Duration: ~ (local time) (100 minutes) Back to Home

Submission #1463360

Source Code Expand

Copy
```import java.io.*;
import java.util.*;

public class Main {

private static Scanner sc;
private static Printer pr;

private static void solve() {
int n = sc.nextInt();
int m = sc.nextInt();

List<List<Integer>> edges = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
}
for (int i = 0; i < m; i++) {
int a = sc.nextInt() - 1;
int b = sc.nextInt() - 1;
}

int[] d = new int[n];
Queue<Integer> q = new ArrayDeque<>();
while (!q.isEmpty()) {
int e = q.remove();

if (d[e] == 2) {
continue;
}

for (int next : edges.get(e)) {
if (next != 0 && d[next] == 0) {
d[next] = d[e] + 1;
}
if (next == n - 1 && d[e] == 1) {
d[next] = d[e] + 1;
}
}
}

if (d[n - 1] == 2) {
pr.println("POSSIBLE");
} else {
pr.println("IMPOSSIBLE");
}
}

// ---------------------------------------------------
public static void main(String[] args) {
sc = new Scanner(System.in);
pr = new Printer(System.out);

solve();

pr.close();
sc.close();
}

@SuppressWarnings("unused")
private static class Scanner {

Scanner (InputStream in) {
}

private boolean isPrintable(int ch) {
return ch >= '!' && ch <= '~';
}

private boolean isCRLF(int ch) {
return ch == '\n' || ch == '\r' || ch == -1;
}

private int nextPrintable() {
try {
int ch;
while (!isPrintable(ch = br.read())) {
if (ch == -1) {
throw new NoSuchElementException();
}
}

return ch;
} catch (IOException e) {
throw new NoSuchElementException();
}
}

String next() {
try {
int ch = nextPrintable();
StringBuilder sb = new StringBuilder();
do {
sb.appendCodePoint(ch);
} while (isPrintable(ch = br.read()));

return sb.toString();
} catch (IOException e) {
throw new NoSuchElementException();
}
}

int nextInt() {
try {
// parseInt from Integer.parseInt()
boolean negative = false;
int res = 0;
int limit = -Integer.MAX_VALUE;
int radix = 10;

int fc = nextPrintable();
if (fc < '0') {
if (fc == '-') {
negative = true;
limit = Integer.MIN_VALUE;
} else if (fc != '+') {
throw new NumberFormatException();
}
}
int multmin = limit / radix;

int ch = fc;
do {
int digit = ch - '0';
if (digit < 0 || digit >= radix) {
throw new NumberFormatException();
}
if (res < multmin) {
throw new NumberFormatException();
}
if (res < limit + digit) {
throw new NumberFormatException();
}
res -= digit;

} while (isPrintable(ch = br.read()));

return negative ? res : -res;
} catch (IOException e) {
throw new NoSuchElementException();
}
}

long nextLong() {
try {
// parseLong from Long.parseLong()
boolean negative = false;
long res = 0;
long limit = -Long.MAX_VALUE;
int radix = 10;

int fc = nextPrintable();
if (fc < '0') {
if (fc == '-') {
negative = true;
limit = Long.MIN_VALUE;
} else if (fc != '+') {
throw new NumberFormatException();
}
}
long multmin = limit / radix;

int ch = fc;
do {
int digit = ch - '0';
if (digit < 0 || digit >= radix) {
throw new NumberFormatException();
}
if (res < multmin) {
throw new NumberFormatException();
}
if (res < limit + digit) {
throw new NumberFormatException();
}
res -= digit;

} while (isPrintable(ch = br.read()));

return negative ? res : -res;
} catch (IOException e) {
throw new NoSuchElementException();
}
}

float nextFloat() {
return Float.parseFloat(next());
}

double nextDouble() {
return Double.parseDouble(next());
}

String nextLine() {
try {
int ch;
while (isCRLF(ch = br.read())) {
if (ch == -1) {
throw new NoSuchElementException();
}
}
StringBuilder sb = new StringBuilder();
do {
sb.appendCodePoint(ch);
} while (!isCRLF(ch = br.read()));

return sb.toString();
} catch (IOException e) {
throw new NoSuchElementException();
}
}

void close() {
try {
br.close();
} catch (IOException e) {
//				throw new NoSuchElementException();
}
}
}

private static class Printer extends PrintWriter {
Printer(PrintStream out) {
super(out);
}
}
}
```

#### Submission Info

Submission Time 2017-07-29 21:09:49+0900 C - Cat Snuke and a Voyage garnacha Java8 (OpenJDK 1.8.0) 300 4858 Byte AC 370 ms 69696 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
 AC × 4
 AC × 11
Set Name Test Cases
Sample example0, example1, example2, example3
All example0, example1, example2, example3, last0, last1, many0, many1, rand0, rand1, rand2
Case Name Status Exec Time Memory
example0 71 ms 20820 KB
example1 70 ms 19284 KB
example2 100 ms 22740 KB
example3 69 ms 20436 KB
last0 301 ms 56756 KB
last1 308 ms 57396 KB
many0 352 ms 67596 KB
many1 370 ms 69696 KB
rand0 251 ms 55352 KB
rand1 287 ms 56780 KB
rand2 264 ms 53992 KB