Submission details
Task:Denominations
Sender:david.meichel
Submission time:2018-09-15 19:26:33 +0300
Language:Java
Status:READY
Result:
Test results
testverdicttime
#10.28 sdetails
#20.27 sdetails
#30.26 sdetails
#40.29 sdetails
#50.64 sdetails
#60.63 sdetails
#70.66 sdetails
#80.65 sdetails
#90.65 sdetails
#100.65 sdetails
#110.65 sdetails
#12UNKNOWN--details
#13UNKNOWN--details
#14UNKNOWN--details
#15UNKNOWN--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:

input
15
1 2 5 10 20 50 100 200 500 100...

correct output
ALL

user output
0
time: 0.076507614

Test 2

Verdict:

input
9
2 3 4 5 6 7 8 9 10

correct output
1

user output
0
time: 0.076457076

Test 3

Verdict:

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:

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:

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:

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:

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:

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:

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:

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:

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)