CSES - Aalto Competitive Programming 2024 - wk7 - Mon - Results
Submission details
Task:Road blockade
Sender:louaha1
Submission time:2024-10-21 17:48:30 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void dfs(int, int, int&)':
input/code.cpp:21:44: error: 'n' was not declared in this scope
   21 |             if (low[to] > tin[v] && (to == n || v == n)) {
      |                                            ^

Code

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 100005;

vector<pair<int, int>> adj[MAXN];
int tin[MAXN], low[MAXN], timer;
vector<int> bridges;

void dfs(int v, int p, int& result) {
    tin[v] = low[v] = ++timer;
    for (auto edge : adj[v]) {
        int to = edge.first;
        int id = edge.second;
        if (to == p) continue;
        if (tin[to]) {
            low[v] = min(low[v], tin[to]);
        } else {
            dfs(to, v, result);
            low[v] = min(low[v], low[to]);
            if (low[to] > tin[v] && (to == n || v == n)) {
                result = id;
            }
        }
    }
}

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

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].emplace_back(b, i + 1);
        adj[b].emplace_back(a, i + 1);
    }

    int result = 0;
    dfs(1, -1, result);

    cout << result << endl;
    return 0;
}