git reimport
This commit is contained in:
73
archive/2016.09/2016.09.19 - unsorted/L.java
Normal file
73
archive/2016.09/2016.09.19 - unsorted/L.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class L {
|
||||
int[] bfs(List<List<Integer>> edges, int from) {
|
||||
int n = edges.size();
|
||||
int[] res = new int[n];
|
||||
Arrays.fill(res, n + 100);
|
||||
res[from] = 0;
|
||||
|
||||
boolean[] visited = new boolean[n];
|
||||
visited[from] = true;
|
||||
|
||||
Queue<Integer> queue = new LinkedList<>();
|
||||
queue.add(from);
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
int a = queue.poll();
|
||||
for (int b : edges.get(a)) {
|
||||
if (!visited[b]) {
|
||||
res[b] = res[a] + 1;
|
||||
visited[b] = true;
|
||||
queue.add(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
int n = in.nextInt() + 1;
|
||||
int m = in.nextInt();
|
||||
|
||||
int a = in.nextInt();
|
||||
int b = in.nextInt();
|
||||
|
||||
List<List<Integer>> edges1 = new ArrayList<>();
|
||||
List<List<Integer>> edges2 = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
edges1.add(new ArrayList<>());
|
||||
edges2.add(new ArrayList<>());
|
||||
}
|
||||
|
||||
for (int i = 0; i < m; i++) {
|
||||
int v1 = in.nextInt();
|
||||
int v2 = in.nextInt();
|
||||
edges1.get(v1).add(v2);
|
||||
edges2.get(v2).add(v1);
|
||||
}
|
||||
|
||||
int[] toPivot = bfs(edges1, 0);
|
||||
int[] fromA = bfs(edges2, a);
|
||||
int[] fromB = bfs(edges2, b);
|
||||
|
||||
int res = n + 100;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
res = Math.min(res, toPivot[i] + fromA[i] + fromB[i]);
|
||||
}
|
||||
|
||||
out.println(res);
|
||||
}
|
||||
}
|
43
archive/2016.09/2016.09.19 - unsorted/L.task
Normal file
43
archive/2016.09/2016.09.19 - unsorted/L.task
Normal file
@@ -0,0 +1,43 @@
|
||||
1 L
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
2
|
||||
0
|
||||
39 6 8 4 6
|
||||
0 1
|
||||
0 2
|
||||
1 2
|
||||
1 5
|
||||
2 3
|
||||
2 4
|
||||
3 6
|
||||
5 6
|
||||
1 4
|
||||
1
|
||||
1
|
||||
31 4 6 3 4
|
||||
0 1
|
||||
0 2
|
||||
1 3
|
||||
2 4
|
||||
3 4
|
||||
4 3
|
||||
1 3
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.L
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2016.09.19
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
78
archive/2016.09/2016.09.19 - unsorted/M.java
Normal file
78
archive/2016.09/2016.09.19 - unsorted/M.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class M {
|
||||
boolean ask(InputReader in, OutputWriter out, int i, int j) {
|
||||
out.println("? " + i + " " + j);
|
||||
out.flush();
|
||||
return in.nextLine().charAt(0) == '<';
|
||||
}
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
int n = Integer.parseInt(in.nextLine());
|
||||
|
||||
int m = Integer.highestOneBit(n) * 2;
|
||||
int[] a = new int[2 * m];
|
||||
Arrays.fill(a, -1);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
a[m + i] = i + 1;
|
||||
}
|
||||
|
||||
for (int i = m - 1; i >= 1; i--) {
|
||||
int c1 = a[2 * i];
|
||||
int c2 = a[2 * i + 1];
|
||||
|
||||
if (c2 == -1 || c1 == -1) {
|
||||
a[i] = c1;
|
||||
continue;
|
||||
}
|
||||
|
||||
a[i] = ask(in, out, c1, c2) ? c2 : c1;
|
||||
}
|
||||
|
||||
int p = 1;
|
||||
|
||||
Queue<Integer> candidates = new LinkedList<>();
|
||||
|
||||
while (true) {
|
||||
int c1 = p * 2;
|
||||
int c2 = p * 2 + 1;
|
||||
|
||||
if (c1 >= 2 * m || c2 >= 2 * m) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (a[c2] == a[p]) {
|
||||
int t = c1;
|
||||
c1 = c2;
|
||||
c2 = t;
|
||||
}
|
||||
|
||||
if (a[c2] != -1) {
|
||||
candidates.add(a[c2]);
|
||||
}
|
||||
p = c1;
|
||||
}
|
||||
|
||||
while (candidates.size() > 1) {
|
||||
int a1 = candidates.poll();
|
||||
int a2 = candidates.poll();
|
||||
|
||||
if (ask(in, out, a1, a2)) {
|
||||
candidates.add(a2);
|
||||
} else {
|
||||
candidates.add(a1);
|
||||
}
|
||||
}
|
||||
|
||||
out.println("! " + candidates.poll());
|
||||
out.flush();
|
||||
}
|
||||
}
|
21
archive/2016.09/2016.09.19 - unsorted/M.task
Normal file
21
archive/2016.09/2016.09.19 - unsorted/M.task
Normal file
@@ -0,0 +1,21 @@
|
||||
1 M
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
0
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.M
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2016.09.19
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
9
archive/2016.09/2016.09.20 - unsorted/M2.java
Normal file
9
archive/2016.09/2016.09.20 - unsorted/M2.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package chelper;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class M2 {
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
}
|
||||
}
|
21
archive/2016.09/2016.09.20 - unsorted/M2.task
Normal file
21
archive/2016.09/2016.09.20 - unsorted/M2.task
Normal file
@@ -0,0 +1,21 @@
|
||||
2 M2
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
0
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
10 chelper.M2
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2016.09.20
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
Reference in New Issue
Block a user