4
4
import java .io .FileWriter ;
5
5
import java .io .IOException ;
6
6
import java .io .PrintWriter ;
7
- import java .util .Scanner ;
7
+ import java .lang .Math ;
8
+ import java .text .CollationElementIterator ;
8
9
import java .util .ArrayList ;
10
+ import java .util .Arrays ;
9
11
import java .util .Collections ;
12
+ import java .util .LinkedList ;
13
+ import java .util .Queue ;
14
+ import java .util .Scanner ;
10
15
11
16
public class Main {
12
17
static class Task {
@@ -16,6 +21,9 @@ static class Task {
16
21
// numarul maxim de noduri
17
22
public static final int NMAX = 1005 ;
18
23
24
+ // valoare mai mare decat maxFlow
25
+ public static final int INF = (int ) 10e9 ;
26
+
19
27
// n = numar de noduri, m = numar de muchii
20
28
int n , m ;
21
29
@@ -24,7 +32,30 @@ static class Task {
24
32
ArrayList <Integer > adj [] = new ArrayList [NMAX ];
25
33
26
34
// cap[i][j] = capacitatea arcului i -> j
27
- int cap [][];
35
+ int c [][];
36
+
37
+ public class Edge {
38
+ public int node ;
39
+ public int neigh ;
40
+
41
+ Edge (int _node , int _neigh ) {
42
+ node = _node ;
43
+ neigh = _neigh ;
44
+ }
45
+
46
+ }
47
+
48
+ // structura folosita pentru a stoca daca exista drum de ameliorare
49
+ // si care este acesta.
50
+ public class AugmentedPath {
51
+ boolean hasPath ;
52
+ ArrayList <Edge > path ;
53
+
54
+ AugmentedPath (boolean _hasPath , ArrayList <Edge > _path ) {
55
+ hasPath = _hasPath ;
56
+ path = _path ;
57
+ }
58
+ }
28
59
29
60
public void solve () {
30
61
readInput ();
@@ -34,27 +65,29 @@ public void solve() {
34
65
private void readInput () {
35
66
try {
36
67
Scanner sc = new Scanner (new BufferedReader (new FileReader (
37
- INPUT_FILE )));
68
+ INPUT_FILE )));
38
69
n = sc .nextInt ();
39
70
m = sc .nextInt ();
40
71
41
- cap = new int [n + 1 ][n + 1 ];
42
72
for (int i = 1 ; i <= n ; i ++) {
43
73
adj [i ] = new ArrayList <>();
44
74
}
75
+
76
+ c = new int [n + 1 ][n + 1 ];
77
+
45
78
for (int i = 1 ; i <= m ; i ++) {
46
79
// x -> y de capacitate c
47
- int x , y , c ;
48
- x = sc .nextInt ();
49
- y = sc .nextInt ();
50
- c = sc .nextInt ();
51
- adj [x ].add (y );
52
- adj [y ].add (x );
80
+ int u , v , capacity ;
81
+ u = sc .nextInt ();
82
+ v = sc .nextInt ();
83
+ capacity = sc .nextInt ();
84
+ adj [u ].add (v );
85
+ adj [v ].add (u );
53
86
54
87
// Presupunem existenta mai multor arce x -> y cu capacitati c1, c2, ...
55
88
// Comprimam intr-un singur arc x -> y cu capacitate
56
89
// cap[x][y] = c1 + c2 + ...
57
- cap [ x ][ y ] += c ;
90
+ c [ u ][ v ] += capacity ;
58
91
}
59
92
sc .close ();
60
93
} catch (IOException e ) {
@@ -65,7 +98,7 @@ private void readInput() {
65
98
private void writeOutput (int result ) {
66
99
try {
67
100
PrintWriter pw = new PrintWriter (new BufferedWriter (new FileWriter (
68
- OUTPUT_FILE )));
101
+ OUTPUT_FILE )));
69
102
pw .printf ("%d\n " , result );
70
103
pw .close ();
71
104
} catch (IOException e ) {
@@ -80,16 +113,15 @@ private int getResult() {
80
113
// Destinatia este nodul n.
81
114
//
82
115
// In adj este stocat graful neorientat obtinut dupa ce se elimina orientarea
83
- // arcelor, iar in cap sunt stocate capacitatile arcelor.
84
- // De exemplu, un arc (x, y) de capacitate z va fi tinut astfel:
85
- // cap [x][y] = z , adj[x] contine y, adj[y] contine x.
116
+ // arcelor, iar in c sunt stocate capacitatile arcelor.
117
+ // De exemplu, un arc (x, y) de capacitate cap va fi tinut astfel:
118
+ // c [x][y] = cap , adj[x] contine y, adj[y] contine x.
86
119
//
87
- int maxFlow = 0 ;
88
-
89
- return maxFlow ;
120
+ int totalFlow = 0 ;
121
+ return totalFlow ;
90
122
}
91
- }
92
123
124
+ }
93
125
public static void main (String [] args ) {
94
126
new Task ().solve ();
95
127
}
0 commit comments