| Task: | Denominations |
| Sender: | david.meichel |
| Submission time: | 2018-09-15 19:26:33 +0300 |
| Language: | Java |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.28 s | details |
| #2 | WRONG ANSWER | 0.27 s | details |
| #3 | WRONG ANSWER | 0.26 s | details |
| #4 | WRONG ANSWER | 0.29 s | details |
| #5 | RUNTIME ERROR | 0.64 s | details |
| #6 | RUNTIME ERROR | 0.63 s | details |
| #7 | RUNTIME ERROR | 0.66 s | details |
| #8 | RUNTIME ERROR | 0.65 s | details |
| #9 | RUNTIME ERROR | 0.65 s | details |
| #10 | RUNTIME ERROR | 0.65 s | details |
| #11 | RUNTIME ERROR | 0.65 s | details |
| #12 | UNKNOWN | -- | details |
| #13 | UNKNOWN | -- | details |
| #14 | UNKNOWN | -- | details |
| #15 | UNKNOWN | -- | details |
Code
import java.util.*;
public class Task2
{
public static void main(String[] args)
{
long startTime = System.nanoTime();
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int m = s.nextInt();
long tmp_flow;
long[][] am = new long [n+1][n+1];
long flow = 0;
for(int i = 0; i < m; i++)
{
int x = s.nextInt();
int y = s.nextInt();
am[x][y] = s.nextInt();
}
double path_sum_timer = 0;
List<Integer> visited = new ArrayList<Integer>();
List<Integer> track = new ArrayList<Integer>();
List<Integer> path = find_path(am, 1, n, visited, track);
visited = new ArrayList<Integer>();
track = new ArrayList<Integer>();
while(path.size() != 0)
{
tmp_flow = flow_of_path(am, path);
flow += tmp_flow;
am = switch_edges(am,path, tmp_flow);
path = find_path(am, 1, n, visited, track);
visited = new ArrayList<Integer>();
track = new ArrayList<Integer>();
}
System.out.println(flow);
long endTime = System.nanoTime();
long totalTime = endTime - startTime;
double seconds = (double)totalTime / 1000000000.0;
System.out.println("time: " + seconds);
}
public static long[][] switch_edges(long [][] am, List<Integer> path, long flow)
{
for (int i = 0; i < path.size()-1; i++)
{
int x = path.get(i);
int y = path.get(i+1);
am[x][y] = am[x][y] - flow;
am[y][x] += flow;
}
return am;
}
public static long flow_of_path(long[][] am, List<Integer> path)
{
long flow = Long.MAX_VALUE;
for (int i = 0; i < path.size()-1; i++)
{
int x = path.get(i);
int y = path.get(i+1);
if(am[x][y] < flow)
flow = am[x][y];
}
return flow;
}
public static List<Integer> find_path(long[][] am, int source, int target, List<Integer> visited, List<Integer> track)
{
visited.add(source);
for(int i = 1; i < am[source].length; i++)
{
if(am[source][i] != 0 && !visited.contains(i))
{
if(i == target)
{
track.add(0, target);
track.add(0, source);
return track;
}
else
{
List<Integer> track_from_i = find_path(am, i, target, visited, track);
if(track_from_i.contains(target))
{
track.add(0, source);
return track;
}
}
}
}
return (new ArrayList<Integer>());
}
public static void printam(int[][] am)
{
for(int i = 0; i < am.length; i++)
{
for(int j = 0; j < am[i].length; j++)
System.out.print(am[i][j]);
System.out.println("");
}
}
}
Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 15 1 2 5 10 20 50 100 200 500 100... |
| correct output |
|---|
| ALL |
| user output |
|---|
| 0 time: 0.076507614 |
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 9 2 3 4 5 6 7 8 9 10 |
| correct output |
|---|
| 1 |
| user output |
|---|
| 0 time: 0.076457076 |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 99 2 3 4 5 6 7 8 9 10 11 12 13 14... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 0 time: 0.076283631 |
Test 4
Verdict: WRONG ANSWER
| input |
|---|
| 999 2 3 4 5 6 7 8 9 10 11 12 13 14... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 0 time: 0.089442517 |
Test 5
Verdict: RUNTIME ERROR
| input |
|---|
| 9999 2 3 4 5 6 7 8 9 10 11 12 13 14... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at Task2.main(Task...
Test 6
Verdict: RUNTIME ERROR
| input |
|---|
| 99999 2 3 4 5 6 7 8 9 10 11 12 13 14... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at Task2.main(Task...
Test 7
Verdict: RUNTIME ERROR
| input |
|---|
| 999999 2 3 4 5 6 7 8 9 10 11 12 13 14... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at Task2.main(Task...
Test 8
Verdict: RUNTIME ERROR
| input |
|---|
| 999999 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
| correct output |
|---|
| ALL |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at Task2.main(Task...
Test 9
Verdict: RUNTIME ERROR
| input |
|---|
| 1000000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
| correct output |
|---|
| ALL |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at Task2.main(Task...
Test 10
Verdict: RUNTIME ERROR
| input |
|---|
| 1000000 1 487 820 4599 6672 7832 8293 ... |
| correct output |
|---|
| ALL |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at Task2.main(Task...
Test 11
Verdict: RUNTIME ERROR
| input |
|---|
| 1000000 628 2499 2887 3482 4061 5947 7... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at Task2.main(Task...
Test 12
Verdict: UNKNOWN
| input |
|---|
| 1 1 |
| correct output |
|---|
| ALL |
| user output |
|---|
| (not available) |
Test 13
Verdict: UNKNOWN
| input |
|---|
| 1 2 |
| correct output |
|---|
| 1 |
| user output |
|---|
| (not available) |
Test 14
Verdict: UNKNOWN
| input |
|---|
| 1 1000000000 |
| correct output |
|---|
| 1 |
| user output |
|---|
| (not available) |
Test 15
Verdict: UNKNOWN
| input |
|---|
| 2 5 6 |
| correct output |
|---|
| 1 |
| user output |
|---|
| (not available) |
