Network POJ 1144

该程序解决了一个图论问题,即在一个电话线路网络中,当某个节点断电时,可能导致其他部分无法通信的节点被称为关键节点(割点)。程序通过DFS遍历所有节点,确定哪些节点的失效能导致网络分割。输入包含多个网络实例,每个实例的节点和连接关系,输出每个实例中割点的数量。示例输入和输出分别展示了如何处理网络并找出割点。

Description A Telephone Line Company (TLC) is establishing a new
telephone cable network. They are connecting several places numbered
by integers from 1 to N . No two places have the same number. The
lines are bidirectional and always connect together two places and in
each place the lines end in a telephone exchange. There is one
telephone exchange in each place. From each place it is possible to
reach through lines every other place, however it need not be a direct
connection, it can go through several exchanges. From time to time the
power supply fails at a place and then the exchange does not operate.
The officials from TLC realized that in such a case it can happen that
besides the fact that the place with the failure is unreachable, this
can also cause that some other places cannot connect to each other. In
such a case we will say the place (where the failure occured) is
critical. Now the officials are trying to write a program for finding
the number of all such critical places. Help them.

Input The input file consists of several blocks of lines. Each block
describes one network. In the first line of each block there is the
number of places N < 100. Each of the next at most N lines contains
the number of a place followed by the numbers of some places to which
there is a direct line from this place. These at most N lines
completely describe the network, i.e., each direct connection of two
places in the network is contained at least in one row. All numbers in
one line are separated by one space. Each block ends with a line
containing just 0. The last block has only one line with N = 0;

Output The output contains for each block except the last in the input
file one line containing the number of critical places.

Sample Input

5
5 1 2 3 4
0
6 2 1 3
5 4 6 2
0
0

Sample Output

1
2

题意:输入一个图,求割点数目。
判断割点的板子题。num数组存dfs搜索时的序列,low存当前节点的子节点能返回的最小根节点。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EnewPosstr 1e-9
#define newPosI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int maxn = 10005;
struct Edge {
    int to, next;
}edge[maxn];
int dfn,ans;
int head[maxn];
int p[maxn];
int cnt;
int vis[maxn];
int low[maxn], num[maxn];
int child ;
void init() {
    cnt = 0;
    child = 0;
    for (int i = 0; i < maxn; i++)
    {
        p[i] = 0;
        head[i] = -1;
        edge[i].next = -1;
        vis[i] = 0;
        low[i] = 0;
     //   num[i]=0;
    }
    dfn = 0;
    ans = 0;
}
void add(int u, int v)
{
    edge[cnt].to = v;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}
void dfs(int u,int fa)
{
    vis[u] = 1;
    num[u] = low[u] = ++dfn;
    for (int i = head[u]; i != -1; i = edge[i].next)
    {
        int f = edge[i].to;
        if (!vis[f])
        {
            if(u==1)                 //判断根有几个子节点。
            child++;
            dfs(f, u);
            low[u] = min(low[f], low[u]);     
            //更新当前节点的子节点所能回到的最小根,当搜完一条路径返回时更新(逆序更新)。
            if (low[f] >= num[u] && u != 1)   
                //如果搜索的这条路径没有回边,侧u为割点。
                p[u] = 1;
        }
        else if (num[f] < num[u] && f != fa)   //如果发现回边,更新low值。
        {
            low[u] = min(low[u], num[f]);
        }
        if (u == 1 && child >= 2)
            p[1] = 1;
    }
    return;
}
int main() 
{
    int n;
    while (cin >> n&&n)
    {
        init();
        int a;
        int b;
        while (scanf_s("%d",&a)&&a)
        {
            while (getchar() != '\n')
            {
                scanf_s("%d", &b);
                add(a, b);
                add(b, a);
            }
        }
        dfs(1, -1);
        for (int i = 1; i <= n; i++)
            if (p[i])ans++;
        cout << ans << endl;
    }
    return 0;
}

考虑柔性负荷的综合能源系统低碳经济优化调度【考虑碳交易机制】(Matlab代码实现)内容概要:本文围绕“考虑柔性负荷的综合能源系统低碳经济优化调度”展开,重研究在碳交易机制下如何实现综合能源系统的低碳化与经济性协同优化。通过构建包含风电、光伏、储能、柔性负荷等多种能源形式的系统模型,结合碳交易成本与能源调度成本,提出优化调度策略,以降低碳排放并提升系统运行经济性。文中采用Matlab进行仿真代码实现,验证了所提模型在平衡能源供需、平抑可再生能源波动、引导柔性负荷参与调度等方面的有效性,为低碳能源系统的设计与运行提供了技术支撑。; 适合人群:具备一定电力系统、能源系统背景,熟悉Matlab编程,从事能源优化、低碳调度、综合能源系统等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①研究碳交易机制对综合能源系统调度决策的影响;②实现柔性负荷在削峰填谷、促进可再生能源消纳中的作用;③掌握基于Matlab的能源系统建模与优化求解方法;④为实际综合能源项目提供低碳经济调度方案参考。; 阅读建议:建议读者结合Matlab代码深入理解模型构建与求解过程,重关注目标函数设计、约束条件设置及碳交易成本的量化方式,可进一步扩展至多能互补、需求响应等场景进行二次开发与仿真验证。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值