| Task: | Download Speed |
| Sender: | Wuppfler |
| Submission time: | 2026-10-11 15:55:53 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.00 s | details |
| #3 | ACCEPTED | 0.00 s | details |
| #4 | ACCEPTED | 0.00 s | details |
| #5 | WRONG ANSWER | 0.01 s | details |
| #6 | WRONG ANSWER | 0.04 s | details |
| #7 | WRONG ANSWER | 2.50 s | details |
| #8 | WRONG ANSWER | 0.00 s | details |
| #9 | ACCEPTED | 0.00 s | details |
| #10 | ACCEPTED | 0.00 s | details |
| #11 | ACCEPTED | 0.01 s | details |
| #12 | ACCEPTED | 0.00 s | details |
Compiler report
input/code.cpp: In function 'void adjust_weights(std::vector<int>&, std::vector<std::vector<long unsigned int> >&)':
input/code.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int i = 1; i < path.size(); ++i) {
| ~~^~~~~~~~~~~~~
input/code.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 1; i < path.size(); ++i) {
| ~~^~~~~~~~~~~~~Code
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <stack>
#include <functional>
std::vector<int> find_positive_path(int start, int end, std::vector<std::vector<int>> &edges, std::vector<std::vector<uint64_t>> &weights) {
std::vector<bool> visited(edges.size(), false);
std::function<std::vector<int>(int, int)> recurse = [&edges, &weights, &visited, &recurse](int start, int end) -> std::vector<int> {
if (start == end) return {end};
visited[start] = true;
std::vector<int> path;
path.push_back(start);
//std::cout << "Adding " << start+1 << std::endl;
for (auto &edge : edges[start]) {
if (visited[edge]) continue;
if (weights[start][edge] == 0) continue;
//std::cout << "Checking edge " << start+1 << " " << edge+1 << std::endl;
std::vector<int> rescursed_path = recurse(edge, end);
if (rescursed_path.size() > 0) {
path.insert(path.end(), rescursed_path.begin(), rescursed_path.end());
break;
}
//std::cout << "No valid path with " << edge+1 << std::endl;
}
if (path.size() == 1) {
//std::cout << "Removing " << start+1 << std::endl;
visited[start] = false;
return {};
};
//std::cout << "Found path" << std::endl;
return path;
};
return recurse(start, end);
}
void adjust_weights(std::vector<int> &path, std::vector<std::vector<uint64_t>> &weights) {
//std::cout << "Adjusting Path: ";
uint64_t min_weight = UINT64_MAX;
for (int i = 1; i < path.size(); ++i) {
min_weight = std::min(min_weight, weights[path[i-1]][path[i]]);
//std::cout << path[i-1]+1 << " ";
}
//std::cout << path[path.size()-1]+1 << std::endl;
//std::cout << "minimum weight: " << min_weight << std::endl;
for (int i = 1; i < path.size(); ++i) {
weights[path[i-1]][path[i]] -= min_weight;
weights[path[i]][path[i-1]] += min_weight;
}
}
int main() {
int n, m;
std::cin >> n >> m;
std::vector<std::vector<int>> edges(n);
std::vector<std::vector<uint64_t>> weights(n, std::vector<uint64_t>(n, 0));
for (int i = 0; i < m; ++i) {
int a, b;
uint64_t c;
std::cin >> a >> b >> c;
edges[a-1].push_back(b-1);
edges[b-1].push_back(a-1);
weights[a-1][b-1] = c;
}
bool is_max_flow = false;
while(!is_max_flow) {
std::vector<int> path = find_positive_path(0, n-1, edges, weights);
if (path.size() == 0) {
is_max_flow = true;
continue;
}
adjust_weights(path, weights);
}
uint64_t max_flow = -weights[n-1][0];
for (auto &edge : edges[0]) {
max_flow += weights[edge][0];
}
std::cout << max_flow << std::endl;
}Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 4 3 1 2 5 2 3 3 3 4 6 |
| correct output |
|---|
| 3 |
| user output |
|---|
| 3 |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 4 5 1 2 1 1 3 1 2 3 1 2 4 1 ... |
| correct output |
|---|
| 2 |
| user output |
|---|
| 2 |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 4 5 1 2 1000000000 1 3 1000000000 2 3 1 2 4 1000000000 ... |
| correct output |
|---|
| 2000000000 |
| user output |
|---|
| 2000000000 |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 2 1 2 1 100 |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 2 1000 1 2 1000000000 1 2 1000000000 1 2 1000000000 1 2 1000000000 ... |
| correct output |
|---|
| 1000000000000 |
| user output |
|---|
| 999000000000 |
Feedback: Incorrect character on line 1 col 1: expected "1000000000000", got "999000000000"
Test 6
Verdict: WRONG ANSWER
| input |
|---|
| 500 998 1 2 54 1 3 59 1 4 83 2 5 79 ... |
| correct output |
|---|
| 60 |
| user output |
|---|
| 120 |
Feedback: Incorrect character on line 1 col 1: expected "60", got "120"
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 500 998 1 2 530873053 1 3 156306296 1 4 478040476 3 5 303609600 ... |
| correct output |
|---|
| 1093765123 |
| user output |
|---|
| 2121648231 |
Feedback: Incorrect character on line 1 col 1: expected "1093765123", got "2121648231"
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 2 1 1 2 1 |
| correct output |
|---|
| 1 |
| user output |
|---|
| 0 |
Feedback: Incorrect character on line 1 col 1: expected "1", got "0"
Test 9
Verdict: ACCEPTED
| input |
|---|
| 4 5 1 2 3 2 4 2 1 3 4 3 4 5 ... |
| correct output |
|---|
| 6 |
| user output |
|---|
| 6 |
Test 10
Verdict: ACCEPTED
| input |
|---|
| 4 5 1 2 1 1 3 2 3 2 1 2 4 2 ... |
| correct output |
|---|
| 3 |
| user output |
|---|
| 3 |
Test 11
Verdict: ACCEPTED
| input |
|---|
| 10 999 1 2 1000000000 1 2 1000000000 1 2 1000000000 1 2 1000000000 ... |
| correct output |
|---|
| 111000000000 |
| user output |
|---|
| 111000000000 |
Test 12
Verdict: ACCEPTED
| input |
|---|
| 7 9 1 2 1 1 3 1 1 4 1 2 5 1 ... |
| correct output |
|---|
| 2 |
| user output |
|---|
| 2 |
