codeforce 385 div1 a

A. Hongcow Builds A Nation
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.

The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governments of the k countries that make up the world.

There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.

Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.

Input
The first line of input will contain three integers n, m and k (1 ≤ n ≤ 1 000, 0 ≤ m ≤ 100 000, 1 ≤ k ≤ n) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.

The next line of input will contain k integers c1, c2, …, ck (1 ≤ ci ≤ n). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.

The following m lines of input will contain two integers ui and vi (1 ≤ ui, vi ≤ n). This denotes an undirected edge between nodes ui and vi.

It is guaranteed that the graph described by the input is stable.

Output
Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.

Examples
input
4 1 2
1 3
1 2
output
2
input
3 3 1
2
1 2
1 3
2 3
output
0
Note
For the first sample test, the graph looks like this:

Vertices 1 and 3 are special. The optimal solution is to connect vertex 4 to vertices 1 and 2. This adds a total of 2 edges. We cannot add any more edges, since vertices 1 and 3 cannot have any path between them.
For the second sample test, the graph looks like this:

We cannot add any more edges to this graph. Note that we are not allowed to add self-loops, and the graph must be simple.

题意:
给你一个无向图,有k个重要的点,这k个点不可以有直接或者间接相连,问最多可以在原有的基础上加几条边???

思路:
首先如果有n个点,那最多有(n-1)*n/2条边,那么我们就可以通过dfs找到一个连通块里面有几个点,几条边,然后再判断这个连通块有没有重要点,有就set一个新的块,没有就把他纳入到无重要点的连通块,然后最后只要选定一个点最多的含重要点的连通块连通,那答案必然最大.

ac代码:

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long LL;
vector<int>MAP[1010];
int n, m, t, k,sum,flag,nod;
struct node {
    int shu;
    int dian;
}arr[1010];
bool book1[1010], book2[1010];
void dfs(int a)
{
    nod++;
    if (book1[a])
        flag = 1;
    book2[a] = 1;
    sum += MAP[a].size();
    for (int i = 0; i < MAP[a].size(); i++)
    {
        if (!book2[MAP[a][i]])
        {
            dfs(MAP[a][i]);
        }
    }
}
bool cmp(node a, node b)
{
    return a.dian > b.dian;
}
int main()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= k; i++)
    {
        int temp;
        cin >> temp;
        book1[temp] = 1;
    }
    for (int i = 1; i <= m; i++)
    {
        int a, b;
        cin >> a >> b;
        MAP[a].push_back(b);
        MAP[b].push_back(a);
    }
    int mark = 0;
    for (int i = 1; i <= n; i++)
    {
        if (!book2[i])
        {
            nod = 0;
            sum = 0;
            flag = 0;
            dfs(i);
            if (flag)
            {
                arr[++mark].dian = nod;
                arr[mark].shu = sum / 2;
            }
            else
            {
                arr[n+1].dian += nod;
                arr[n + 1].shu += (sum) / 2;
            }
        }
    }
    sum = 0;
    for (int i = 1; i <= mark; i++)
    {
        sum += (arr[i].dian*(arr[i].dian - 1) / 2-arr[i].shu);
    }
    if (arr[n + 1].dian != 0)
    {
        sum += (arr[n + 1].dian*(arr[n + 1].dian - 1) / 2 - arr[n + 1].shu);
        sort(arr + 1, arr + 1 + mark, cmp);
        sum += arr[1].dian*arr[n + 1].dian;
    }
    cout << sum << endl;
    return 0;
}
【激光质量检测】利用丝杆与步进电机的组合装置带动光源的移动,完成对光源使用切片法测量其光束质量的目的研究(Matlab代码实现)内容概要:本文研究了利用丝杆与步进电机的组合装置带动光源移动,结合切片法实现对激光光源光束质量的精确测量方法,并提供了基于Matlab的代码实现方案。该系统通过机械装置精确控制光源位置,采集不同截面的光强分布数据,进而分析光束的聚焦特性、发散角、光斑尺寸等关键质量参数,适用于高精度光学检测场景。研究重点在于硬件控制与图像处理算法的协同设计,实现了自动化、高重复性的光束质量评估流程。; 适合人群:具备一定光学基础知识和Matlab编程能力的科研人员或工程技术人员,尤其适合从事激光应用、光电检测、精密仪器开发等相关领域的研究生及研发工程师。; 使用场景及目标:①实现对连续或脉冲激光器输出光束的质量评估;②为激光加工、医疗激光、通信激光等应用场景提供可靠的光束分析手段;③通过Matlab仿真与实际控制对接,验证切片法测量方案的有效性与精度。; 阅读建议:建议读者结合机械控制原理与光学测量理论同步理解文档内容,重点关注步进电机控制逻辑与切片数据处理算法的衔接部分,实际应用时需校准装置并优化采样间距以提高测量精度。
### Codeforces Problem or Contest 998 Information For the specific details on Codeforces problem or contest numbered 998, direct references were not provided within the available citations. However, based on similar structures observed in other contests such as those described where configurations often include constraints like `n` representing numbers of elements with defined ranges[^1], it can be inferred that contest or problem 998 would follow a comparable format. Typically, each Codeforces contest includes several problems labeled from A to F or beyond depending on the round size. Each problem comes with its own set of rules, input/output formats, and constraint descriptions. For instance, some problems specify conditions involving integer inputs for calculations or logical deductions, while others might involve more complex algorithms or data processing tasks[^3]. To find detailed information regarding contest or problem 998 specifically: - Visit the official Codeforces website. - Navigate through past contests until reaching contest 998. - Review individual problem statements under this contest for precise requirements and examples. Additionally, competitive programming platforms usually provide comprehensive documentation alongside community discussions which serve valuable resources when exploring particular challenges or learning algorithmic solutions[^2]. ```cpp // Example C++ code snippet demonstrating how contestants interact with input/output during competitions #include <iostream> using namespace std; int main() { int n; cin >> n; // Process according to problem statement specifics } ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值