Submission details
Task:Download Speed
Sender:Wuppfler
Submission time:2026-10-11 16:34:38 +0300
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.01 sdetails
#6ACCEPTED0.10 sdetails
#7--details
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.01 sdetails
#12ACCEPTED0.00 sdetails

Compiler report

input/code.cpp: In function 'uint64_t 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);
}

uint64_t 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;
    }
    return 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;
    uint64_t max_flow = 0;
    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;
        }

        max_flow += adjust_weights(path, weights);
    }

    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: ACCEPTED

input
2 1000
1 2 1000000000
1 2 1000000000
1 2 1000000000
1 2 1000000000
...

correct output
1000000000000

user output
1000000000000

Test 6

Verdict: ACCEPTED

input
500 998
1 2 54
1 3 59
1 4 83
2 5 79
...

correct output
60

user output
60

Test 7

Verdict:

input
500 998
1 2 530873053
1 3 156306296
1 4 478040476
3 5 303609600
...

correct output
1093765123

user output
(empty)

Test 8

Verdict: ACCEPTED

input
2 1
1 2 1

correct output
1

user output
1

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