Submission details
Task:Download Speed
Sender:hundlij1
Submission time:2025-10-19 16:06:58 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp:57:4: error: redefinition of 'll n'
   57 | ll n, m;
      |    ^
input/code.cpp:8:4: note: 'll n' previously declared here
    8 | ll n, maxLog;
      |    ^
input/code.cpp: In function 'll bfs(ll, ll, std::vector<long long int>&)':
input/code.cpp:64:5: error: 'queue' was not declared in this scope
   64 |     queue<pair<ll, ll>> q;
      |     ^~~~~
input/code.cpp:5:1: note: 'std::queue' is defined in header '<queue>'; did you forget to '#include <queue>'?
    4 | #include <cmath>
  +++ |+#include <queue>
    5 | using namespace std;
input/code.cpp:64:22: error: expected primary-expression before '>' token
   64 |     queue<pair<ll, ll>> q;
      |                      ^~
input/code.cpp:64:25: error: 'q' was not declared in this scope
   64 |     queue<pair<ll, ll>> q;
      |                         ^
input/code.cpp:65:16: error: 'LLONG_MAX' was not declared in this scope
   65 |     q.push({s, LLONG_MAX});
      |                ^~~~~~~~~
input/code.cpp:5:1: note: 'L...

Code

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;

ll n, maxLog;
vector<vector<ll>> up;
vector<ll> depth;

void preprocess(vector<ll>& parent) {
    depth[1] = 0;
    for (ll i = 2; i <= n; i++) {
        depth[i] = depth[parent[i]] + 1;
    }
    
    for (ll i = 1; i <= n; i++) {
        up[i][0] = parent[i];
    }
    
    for (ll k = 1; k < maxLog; k++) {
        for (ll node = 1; node <= n; node++) {
            up[node][k] = up[up[node][k-1]][k-1];
        }
    }
}

ll ancestor(ll x, ll k) {
    for (ll i = 0; i < maxLog; i++) {
        if (k & (1 << i)) {
            x = up[x][i];
            if (x == 0) return 0;
        }
    }
    return x;
}

ll lca(ll a, ll b) {
    if (depth[a] < depth[b]) swap(a, b);
    
    a = ancestor(a, depth[a] - depth[b]);
    
    if (a == b) return a;
    
    for (ll k = maxLog - 1; k >= 0; k--) {
        if (up[a][k] != up[b][k]) {
            a = up[a][k];
            b = up[b][k];
        }
    }
    
    return up[a][0];
}


ll n, m;
vector<vector<ll>> capacity;
vector<vector<ll>> adj;

ll bfs(ll s, ll t, vector<ll>& parent) {
    fill(parent.begin(), parent.end(), -1);
    parent[s] = -2;
    queue<pair<ll, ll>> q;
    q.push({s, LLONG_MAX});
    
    while (!q.empty()) {
        ll cur = q.front().first;
        ll flow = q.front().second;
        q.pop();
        
        for (ll next : adj[cur]) {
            if (parent[next] == -1 && capacity[cur][next]) {
                parent[next] = cur;
                ll new_flow = min(flow, capacity[cur][next]);
                if (next == t) return new_flow;
                q.push({next, new_flow});
            }
        }
    }
    
    return 0;
}

ll maxflow(ll s, ll t) {
    ll flow = 0;
    vector<ll> parent(n + 1);
    ll new_flow;
    
    while (new_flow = bfs(s, t, parent)) {
        flow += new_flow;
        ll cur = t;
        while (cur != s) {
            ll prev = parent[cur];
            capacity[prev][cur] -= new_flow;
            capacity[cur][prev] += new_flow;
            cur = prev;
        }
    }
    
    return flow;
}

int main() {
    /*ll q;
    cin >> n >> q;
    maxLog = ceil(log2(n)) + 1;
    up.assign(n + 1, vector<ll>(maxLog, 0));
    depth.assign(n + 1, 0);
    vector<ll> parent(n + 1, 0);

    for(ll i = 2; i <= n; i++){
       cin >> parent[i];
    }

    preprocess(parent);
    
    for(ll i = 0; i < q; i++){
        ll a, b;
        cin >> a >> b;
        cout << lca(a, b) << "\n";
    }

    return 0;*/

     cin >> n >> m;
    capacity.assign(n + 1, vector<ll>(n + 1, 0));
    adj.assign(n + 1, vector<ll>());
    
    for (ll i = 0; i < m; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        capacity[a][b] += c;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    
    cout << maxflow(1, n) << "\n";
    
    return 0;


}