TAPAKAH, Задача ужасно простая, вот написал псевдо код, для копи паста не подойдет, но я бы делал примерно так :
ПС. В коде возможны опечатки - претензии по этому поводу также не принимаются. Сделано на скорую руки (5 минут).
Code
#include <vector>
using namespace std;
// describe how the pole may be ever connected
enum connection_type
{
connection_straight,
connection_parallel,
connection_mixed,
connection_short_curcuit,
connection_nothing
};
// pole information
typedef struct
{
int connection_method;
vector<int> neighbours;
bool connected_to_battery;
} electric_pole;
vector<electric_pole> network;
// Init default network
void init_pole_network()
{
electric_pole p,p1,p2;
// pole 1 connected to battery and to pole 2
p.connection_method = connection_straight;
p.neighbours.push_back(1);
p.connected_to_battery = true;
network.push_back(p);
// pole 2 connected to pole 1 and pole 3
p1.conenction_method = connection_straight;
p1.neighbours.push_back(0);
p1.neighbours.push_back(2);
p1.connected_to_battery = false;
network.push_back(p1);
// pole 3 connected to pole 2 and to battery
p2.conenction_method = connection_straight;
p2.neighbours.push_back(1);
p2.connected_to_battery = true;
network.push_back(p2);
}
// Shut down a pole required
void destroy_pole(int id)
{
network[id].connection_method = connection_nothing;
}
// Check is network OK or ain't
bool update_network()
{
bool result = true;
for(int i=0;i<network.size();i++)
{
if(network[i].connection_method == connection_nothing)
{
result = false;
break;
}
}
return result;
}