Submission #1193317

#TimeUsernameProblemLanguageResultExecution timeMemory
1193317CrabCNHPipes (CEOI15_pipes)C++20
30 / 100
1631 ms131072 KiB
#include <bits/stdc++.h>

#define task   "BriantheCrab"

#define pii    pair <int, int>
#define fi     first
#define se     second
#define szf    sizeof
#define sz(s)  (int)((s).size())

using namespace std;

template <class T> void mini (T &t, T f) {if (t > f) t = f;}
template <class T> void maxi (T &t, T f) {if (t < f) t = f;}

const int maxN = 1e5 + 5;
const int maxM = 6e6 + 5;

int n, m;
int timeDfs = 0;
int low[maxN], num[maxN];

struct Edge {
    int to, nxt, id;
} edges[maxM * 2];

int head[maxN], edgeCnt = 0;

vector <pii> bridges;

void add_edge(int u, int v, int id) {
    edges[edgeCnt] = {v, head[u], id};
    head[u] = edgeCnt++;
}

void dfs(int u, int parent, int parentEdgeId) {
    num[u] = low[u] = ++timeDfs;
    for (int i = head[u]; i != -1; i = edges[i].nxt) {
        int v = edges[i].to;
        int id = edges[i].id;
        if (id == parentEdgeId) continue;
        if (num[v]) {
            mini(low[u], num[v]);
        } else {
            dfs(v, u, id);
            mini(low[u], low[v]);
            if (low[v] > num[u]) {
                bridges.push_back({min(u, v), max(u, v)});
            }
        }
    }
}

void solve() {
    memset(head, -1, sizeof head);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        add_edge(u, v, i);
        add_edge(v, u, i);
    }
    for (int i = 1; i <= n; i++) {
        if (num[i] == 0) {
            dfs(i, i, -1);
        }
    }
    for (auto [x, y] : bridges) {
        cout << x << ' ' << y << '\n';
    }
    return;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
// thfdgb

Compilation message (stderr)

pipes.cpp: In function 'int main()':
pipes.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pipes.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...