This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m;
vector<pair<int, int>> edges, g[N];
bool vis[N];
void dfs(int v, int id){
vis[v] = 1;
for (auto [u, x] : g[v]){
if (x == id or vis[u])
continue;
dfs(u, id);
}
}
int main(){
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++){
int u, v;
cin >> u >> v;
g[u].push_back({v, i});
g[v].push_back({u, i});
edges.push_back({u, v});
}
int orig = 0;
for (int v = 1; v <= n; v++){
if (!vis[v]){
orig++;
dfs(v, m);
}
}
for (int i=0; i<m; i++){
int cc = 0;
for (int v = 1; v <= n; v++)
vis[v] = 0;
for (int v = 1; v <= n; v++){
if (!vis[v]){
cc++;
dfs(v, i);
}
}
if (cc != orig)
cout << edges[i].first << " " << edges[i].second << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |