写个判断把我cpu干烧了
2024-06-26 19:36:12
发布于:上海
A209(寻找道路)写个-1判断,CPU就烧了
请看VCR:
#include <iostream>
#include <vector>
using namespace std;
struct Node
{
int x;
vector<int> m;
};
vector<Node> tree;
int in (vector<Node> tree, int x)
{
for (Node c : tree)
{
if (x == c.x)
{
return 1;
}
}
return 0;
}
void append (int x, int y)
{
for (Node& i : tree)
{
if (i.x == x)
{
vector<int> t(i.m);
t.push_back (y);
i = {x, t};
return;
}
}
}
int main (void)
{
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i ++)
{
int x, y;
cin >> x >> y;
if (in(tree, x))
{
append (x, y);
}
else
{
tree.push_back ({x, {y}});
}
}
int st, ed;
cin >> st >> ed;
bool f = false, fi = false;
for (Node i : tree)
{
if (i.x == st) f = true;
else if (i.x == ed) fi = true;
}
if (f == 0 || fi == 0)
{
cout << -1;
exit (0);
}
}
这里空空如也
有帮助,赞一个