Submission details
Task:Download Speed
Sender:ariadna.roga
Submission time:2025-10-13 16:08:43 +0300
Language:C++ (C++17)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.01 sdetails
#7ACCEPTED0.01 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.01 sdetails
#12ACCEPTED0.00 sdetails

Compiler report

input/code.cpp: In function 'bool there_is_bfs(std::vector<std::vector<long long int> >&, long long int, long long int, std::vector<long long int>&)':
input/code.cpp:25:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (long long i = 0; i < adj.size(); ++i)
      |                               ~~^~~~~~~~~~~~

Code

#include <iostream>
#include <vector>
#include <queue>
#include <climits>

using namespace std;


bool there_is_bfs(vector<vector<long long>> &adj, long long s, long long t, vector<long long> &parent)
{
    // No node has been visited yet
    vector<bool> visited(adj.size(), false);

    // Queue for BFS
    queue<long long> q;
    q.push(s);
    visited[s] = true;
    parent[s] = -1;

    // BFS
    while (!q.empty()) {
        long long u = q.front();
        q.pop();

        for (long long i = 0; i < adj.size(); ++i)
        {
            if (!visited[i] and adj[u][i] > 0) {
                if (i == t) {
                    parent[i] = u;
                    return true;
                }
                q.push(i);
                parent[i] = u;
                visited[i] = true;
            }
        }
    }

    // There is no path
    return false;
}


long long ford_fulkerson(vector<vector<long long>> &graph, long long start, long long end)
{
    vector<long long> parent(graph.size());
    long long max_flow = 0;

    // While there is a path with positive capacities from start to end
    while (there_is_bfs(graph, start, end, parent)) {

        // Calculate path flow for the found path with bfs
        long long path_flow = LLONG_MAX;
        for (long long i = end; i != start; i = parent[i]) {
            long long v = parent[i];
            path_flow = min(path_flow, graph[v][i]);
        }

        // Update max flow
        max_flow += path_flow;

        // Update residual capacities
        for (long long i = end; i != start; i = parent[i]) {
            long long v = parent[i];
            graph[v][i] -= path_flow;
            graph[i][v] += path_flow;
        }
    }

    return max_flow;
}


int main() {
    long long n, m;
    cin >> n >> m;

    // Build graph with capacities
    vector<vector<long long>> capacity(n+1, vector<long long>(n+1, 0));

    for (long long i = 0; i < m; ++i) {
        long long a, b, c;
        cin >> a >> b >> c;
        capacity[a][b] += c;
    }

    // Calculate max flow
    cout << ford_fulkerson(capacity, 1, n) << 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: ACCEPTED

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

correct output
1093765123

user output
1093765123

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