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=5000;
int n;
int cnt[N][N];
bool visited[N];
void dfs(int u) {
visited[u] = true;
for (int v = 0; v < n; v++)
if (cnt[u][v] > 0 && !visited[v])
dfs(v);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(NULL);
int m,u,v;
cin>>n>>m;
while (m-- > 0) {
cin>>u>>v;
u--;
v--;
cnt[u][v]++;
cnt[v][u]++;
}
for (int u = 0; u < n; u++)
for (int v = u + 1; v < n; v++) {
if (cnt[u][v] != 1)
continue;
cnt[u][v] = cnt[v][u] = 0;
for(int i=0;i<n;i++)
visited[i]=false;
dfs(u);
if (!visited[v])
printf("%d %d\n", u + 1, v + 1);
cnt[u][v] = cnt[v][u] = 1;
}
}
# | 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... |