bug
  • 板块P1656 炸铁路
  • 楼主zhp521
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/12/25 10:47
  • 上次更新2024/12/25 18:29:01
查看原帖
bug
1489737
zhp521楼主2024/12/25 10:47
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<array>
using namespace std;
const int N = 155;
const int M = 5005;
using gg = long long;
gg n, m;
gg i = 0;
gg f[N];
vector<array<gg, 2>>ve;
void init()
{
	for (int i = 1; i <= n; i++)f[i] = i;
}

gg find(gg s)
{
	return s == f[s] ? s : f[s]=find(f[s]);
}

void merge(gg a, gg b)
{
	f[find(a)] = find(b);
}
bool cmp(const array<gg, 2>& a, const array<gg, 2>& b)
{
	if (a[0] < b[0])return true;
	else if (a[0] == b[0] and a[1] < b[1])return true;
	else return false;
}
int main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	vector<array<gg, 2>>graph(m);
	for (auto& e : graph)cin >> e[0] >> e[1];
	while (m--)
	{
		init();
		auto p = graph[m];
		for (auto e : graph)
		{
			if (e != p)merge(e[0], e[1]);
		}
		gg num = 0;
		for (int i = 1; i <= n; i++)
		{
			if (i == f[i])num++;
		}
		if (num == 2)ve.push_back(p);
	}
	sort(ve.begin(), ve.end(), cmp);
	for (auto e : ve)cout << e[0] << " " << e[1] << '\n';
}

有没有大佬帮我看看哪里错了?这个是40分

2024/12/25 10:47
加载中...