P1656求调
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
int n, m, nonx, nony;
vector<int> g[160];
int cnt, vis[160];
struct inc
{
int u, v;
} a[50010];
bool cmp(inc x, inc y)
{
if (x.u != y.u)
return x.u < y.u;
return x.v < y.v;
}
void dfs(int x)
{
vis[x] = 1;
for (int y : g[x])
if (!vis[y] && !((x == nonx && y == nony) || (x == nony && y == nonx)))
dfs(y);
}
int main()
{
cin >> n >> m;
for (int i = 1, u, v; i <= m; ++i)
{
cin >> u >> v;
a[i] = {min(u, v), max(u, v)};
g[u].push_back(v);
g[v].push_back(u);
}
sort(a + 1, a + n + 1, cmp);
for (int i = 1; i <= m; ++i)
{
nonx = a[i].u, nony = a[i].v;
memset(vis, 0, sizeof vis);
cnt = 0;
dfs(1);
for (int j = 1; j <= n; ++j)
cnt += vis[j];
}
return 0;
}