| Task: | Internet connection |
| Sender: | kakuro |
| Submission time: | 2018-09-15 14:20:56 +0300 |
| Language: | C++ |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | details |
| #2 | ACCEPTED | 0.02 s | details |
| #3 | ACCEPTED | 0.02 s | details |
| #4 | ACCEPTED | 0.02 s | details |
| #5 | ACCEPTED | 0.01 s | details |
| #6 | WRONG ANSWER | 0.02 s | details |
| #7 | WRONG ANSWER | 0.01 s | details |
| #8 | WRONG ANSWER | 0.02 s | details |
| #9 | WRONG ANSWER | 0.01 s | details |
| #10 | WRONG ANSWER | 0.02 s | details |
Code
#include <iostream>
#include <deque>
#include <algorithm>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef std::string str;
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int edges[n][n];
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
edges[i][j] = 0;
}
}
for(int i=0; i<m; i++) {
int from, to, weight;
cin >> from >> to >> weight;
edges[from-1][to-1] = weight;
}
bool finished = false;
int res = 0;
while(!finished) {
bool explored[n];
int activation[n];
int goesBefore[n];
for(int i=0; i<n; i++) {
explored[i] = false;
activation[i] = 0;
goesBefore[i] = 0;
}
deque<int> queue;
int curExplore = 0;
explored[0] = true;
goesBefore[0] = -1;
activation[0] = 1000000000;
bool reachEnd = false;
//cout << "Hey" << endl;
while(!reachEnd) {
for(int i=0; i<n; i++) {
//cout << "Why" << edges[curExplore][i] << endl;
if(edges[curExplore][i] > 0 && !explored[i]) {
//cout << i << endl;
queue.push_back(i);
explored[i] = true;
goesBefore[i] = curExplore;
activation[i] = min(edges[curExplore][i], activation[curExplore]);
if(i == n-1) {
reachEnd = true;
break;
}
}
}
if(queue.size() == 0 && !reachEnd) {
finished = true;
break;
}
else if(!reachEnd) {
curExplore = queue[0];
queue.pop_front();
}
}
if (reachEnd && !finished) {
int curBackTrack = n-1;
int curSubtract = activation[n-1];
res += curSubtract;
while (curBackTrack != -1) {
int cur = goesBefore[curBackTrack];
edges[cur][curBackTrack] -= curSubtract;
edges[curBackTrack][cur] += curSubtract;
curBackTrack = cur;
}
}
}
cout << res << endl;
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 10 20 5 6 19 4 5 47 3 5 7 4 9 62 ... |
| correct output |
|---|
| 73 |
| user output |
|---|
| 73 |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 10 20 2 4 63 7 9 54 6 7 16 2 3 9 ... |
| correct output |
|---|
| 110 |
| user output |
|---|
| 110 |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 10 20 5 6 90 2 3 46 7 8 80 6 7 60 ... |
| correct output |
|---|
| 29 |
| user output |
|---|
| 29 |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 10 20 3 4 76 5 7 8 3 8 71 4 7 24 ... |
| correct output |
|---|
| 95 |
| user output |
|---|
| 95 |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 10 20 1 8 22 6 7 40 4 5 20 8 10 77 ... |
| correct output |
|---|
| 156 |
| user output |
|---|
| 156 |
Test 6
Verdict: WRONG ANSWER
| input |
|---|
| 100 1000 63 85 864540192 22 91 974117435 64 66 953124912 85 88 6080960 ... |
| correct output |
|---|
| 4397669179 |
| user output |
|---|
| 102701883 |
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 100 1000 36 93 760720873 12 75 175717522 78 79 340128710 80 83 181753465 ... |
| correct output |
|---|
| 5298558023 |
| user output |
|---|
| 1003590727 |
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 100 1000 20 60 909693891 55 91 570199535 21 41 118646902 37 82 824735480 ... |
| correct output |
|---|
| 5466229311 |
| user output |
|---|
| 1171262015 |
Test 9
Verdict: WRONG ANSWER
| input |
|---|
| 100 1000 26 44 753330451 62 67 821574279 70 95 219303983 7 44 980013084 ... |
| correct output |
|---|
| 4893925638 |
| user output |
|---|
| 598958342 |
Test 10
Verdict: WRONG ANSWER
| input |
|---|
| 100 1000 15 89 501388091 50 71 396801720 15 92 324349822 29 85 184420157 ... |
| correct output |
|---|
| 6956499595 |
| user output |
|---|
| -1633434997 |
