Submission details
Task:Internet connection
Sender:TuomoPera
Submission time:2020-09-19 14:56:20 +0300
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#10.01 sdetails
#20.01 sdetails
#30.01 sdetails
#40.01 sdetails
#50.01 sdetails
#6--details
#7--details
#8--details
#9--details
#10--details
#110.01 sdetails
#120.01 sdetails
#130.01 sdetails
#14--details
#150.01 sdetails
#160.01 sdetails
#170.01 sdetails
#18--details
#19--details
#200.01 sdetails
#21--details
#22--details

Code

#include <iostream>
#include <string>

using namespace std;

int g[1000][1000] = {0};
bool visited[1000] = { false };
int end_point = 0;
int result = 0;
bool solution_found = false;


void traverse(int current) {
	if (current == end_point) {
		result += 1;
		solution_found = true;
		return;
	}

	for (int i = 1; i <= end_point; i++) {
		if (g[current][i] > 0 && current != i && !visited[i] && !solution_found) {
			g[current][i] -= 1;
			g[i][current] += 1;
			visited[i] = true;
			traverse(i);
			visited[i] = false;
		}
	}

	/*
	if (g[current][1] > 0 && current != 1 && !visited[1] && !solution_found) {
		g[current][1] -= 1;
		g[1][current] += 1;
		visited[1] = true;
		traverse(1);
		visited[1] = false;
	}
	if (g[current][2] > 0 && current != 2 && !visited[2] && !solution_found) {
		g[current][2] -= 1;
		g[2][current] += 1;
		visited[2] = true;
		traverse(2);
		visited[2] = false;
	}
	if (g[current][3] > 0 && current != 3 && !visited[3] && !solution_found) {
		g[current][3] -= 1;
		g[3][current] += 1;
		visited[3] = true;
		traverse(3);
		visited[3] = false;
	}
	if (g[current][4] > 0 && current != 4 && !visited[4] && !solution_found) {
		g[current][4] -= 1;
		g[4][current] += 1;
		visited[4] = true;
		traverse(4);
		visited[4] = false;
	}
	*/
}

int main() {
	//freopen("cases.txt", "r", stdin);
	int num;
	cin >> end_point >> num;

	for (int i = 0; i < num; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		g[a][b] = c;
	}
	visited[1] = true;

	do {
		solution_found = false;
		traverse(1);
	} while (solution_found);

	return 0;
}

Test details

Test 1

Verdict:

input
10 20
5 6 19
4 5 47
3 5 7
4 9 62
...

correct output
73

user output
(empty)

Test 2

Verdict:

input
10 20
2 4 63
7 9 54
6 7 16
2 3 9
...

correct output
110

user output
(empty)

Test 3

Verdict:

input
10 20
5 6 90
2 3 46
7 8 80
6 7 60
...

correct output
29

user output
(empty)

Test 4

Verdict:

input
10 20
3 4 76
5 7 8
3 8 71
4 7 24
...

correct output
95

user output
(empty)

Test 5

Verdict:

input
10 20
1 8 22
6 7 40
4 5 20
8 10 77
...

correct output
156

user output
(empty)

Test 6

Verdict:

input
100 1000
63 85 864540192
22 91 974117435
64 66 953124912
85 88 6080960
...

correct output
4397669179

user output
(empty)

Test 7

Verdict:

input
100 1000
36 93 760720873
12 75 175717522
78 79 340128710
80 83 181753465
...

correct output
5298558023

user output
(empty)

Test 8

Verdict:

input
100 1000
20 60 909693891
55 91 570199535
21 41 118646902
37 82 824735480
...

correct output
5466229311

user output
(empty)

Test 9

Verdict:

input
100 1000
26 44 753330451
62 67 821574279
70 95 219303983
7 44 980013084
...

correct output
4893925638

user output
(empty)

Test 10

Verdict:

input
100 1000
15 89 501388091
50 71 396801720
15 92 324349822
29 85 184420157
...

correct output
6956499595

user output
(empty)

Test 11

Verdict:

input
2 1
1 2 1

correct output
1

user output
(empty)

Test 12

Verdict:

input
2 1
2 1 1

correct output
0

user output
(empty)

Test 13

Verdict:

input
2 2
1 2 1
2 1 1

correct output
1

user output
(empty)

Test 14

Verdict:

input
100 1000
1 2 539540023
2 3 244306651
3 4 253259012
3 5 630461598
...

correct output
0

user output
(empty)

Test 15

Verdict:

input
4 5
1 2 2
1 3 5
2 4 3
3 2 2
...

correct output
4

user output
(empty)

Test 16

Verdict:

input
2 0

correct output
0

user output
(empty)

Test 17

Verdict:

input
100 0

correct output
0

user output
(empty)

Test 18

Verdict:

input
100 196
1 2 1000000000
2 100 1000000000
1 3 1000000000
3 100 1000000000
...

correct output
98000000000

user output
(empty)

Test 19

Verdict:

input
100 99
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
...

correct output
1000000000

user output
(empty)

Test 20

Verdict:

input
2 2
2 1 1
1 2 1

correct output
1

user output
(empty)

Test 21

Verdict:

input
4 6
1 2 1000000000
1 3 1000000000
2 3 1
2 4 1000000000
...

correct output
2000000000

user output
(empty)

Test 22

Verdict:

input
4 6
1 2 1000000000
1 3 1000000000
2 4 1000000000
2 3 1
...

correct output
2000000000

user output
(empty)