当前位置:网站首页>Divide candy
Divide candy
2022-07-06 21:14:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
Divide candy
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 18 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
In childhood, we will share good things with our friends as our own happiness . On the day ,C The children got candy , I'm going to give these sweets to my best friends . It is known that candy is passed from one person to another who needs 1 The second time , The same child will not accept candy repeatedly . Because there are enough sweets , Suppose a child accepts candy at some time . He will divide the candy into several parts , Give it to the children who are beside him and haven't got candy yet , And I will eat some candy . Because of greediness , The children can't wait to send out the candy , Will eat and distribute after getting candy . Every child needs... From accepting candy to eating it m The second time . that , Suppose the first second C The children began to send sugar , In a few seconds, all the children finished eating sugar ?
Input
Input has multiple sets of data , The data of each group is no 1 Act three numbers n(<=10000),p(<=600000),c Count the children , Relationship number and C Number... Children . The first 2 Behavior a number m(<=8000), It means the time for children to eat sugar . following p Two integers per line , It means that two children are beside each other .
Output
For each set of inputs, output a separate integer representation from Ts To Te The minimum total cost of . Data guarantees that there is at least one path .
Sample Input
4 3 1
2
1 2
2 3
1 4Sample Output
5
Hint
The first second , Sugar in 1 On hand . The second seconds , The sugar reached 2、4 In the hands of . The third second . The sugar reached 3 In the hands of , here 1 I'm full . The fourth second ,2、4 I'm full . The fifth second .3 I'm full . So the answer is 5.Author
HYNU
// The idea is to find out and 1 From the farthest point to 1 Distance of , First, mark the weight of each path as 1. Find the farthest point and add m That's the answer. . Because the last person to eat sugar needs m Time , Suppose this person has finished eating in the end , Then the person in front of him must have finished . When searching, we use the breadth first search of graph , because n A very large . So use vector Dynamic array to store edges .
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
vector<int>num[10001];
queue<int>q;
int vis[10001],f[10001];
void bfs()
{
int i,t;
while(!q.empty())
{
t=q.front();
q.pop();
for(i=0;i<num[t].size();i++)
{
if(!vis[num[t][i]])
{
vis[num[t][i]]=1;
f[num[t][i]]=f[t]+1;
q.push(num[t][i]);
}
}
}
}
int main()
{
int n,p,c,m,i,a,b;
while(scanf("%d%d%d%d",&n,&p,&c,&m)!=EOF)
{
for(i=0;i<=n;i++)
num[i].clear();
memset(vis,0,sizeof(vis));
memset(f,0,sizeof(f));
while(!q.empty()) q.pop();
for(i=0;i<p;i++)
{
scanf("%d%d",&a,&b);
num[a].push_back(b);
num[b].push_back(a);
}
q.push(c);
vis[c]=1;
f[c]=1;
bfs();
int ans=0;
for(i=1;i<=n;i++)
{
if(f[i]>ans) ans=f[i];
//printf("%d\n",f[i]);
}
printf("%d\n",ans+m);
}
return 0;
}Copyright notice : This article is the original article of the blogger . Blog , Do not reprint without permission .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117097.html Link to the original text :https://javaforall.cn
边栏推荐
- 3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
- R语言可视化两个以上的分类(类别)变量之间的关系、使用vcd包中的Mosaic函数创建马赛克图( Mosaic plots)、分别可视化两个、三个、四个分类变量的关系的马赛克图
- In JS, string and array are converted to each other (I) -- the method of converting string into array
- 'class file has wrong version 52.0, should be 50.0' - class file has wrong version 52.0, should be 50.0
- [in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
- OSPF multi zone configuration
- JS traversal array and string
- SAP UI5 框架的 manifest.json
- 967- letter combination of telephone number
- Is it profitable to host an Olympic Games?
猜你喜欢

全网最全的知识库管理工具综合评测和推荐:FlowUs、Baklib、简道云、ONES Wiki 、PingCode、Seed、MeBox、亿方云、智米云、搜阅云、天翎

039. (2.8) thoughts in the ward

for循环中break与continue的区别——break-完全结束循环 & continue-终止本次循环
![[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs](/img/66/4d94ae24e99599891636013ed734c5.png)
[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs

PHP saves session data to MySQL database

ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer

3D face reconstruction: from basic knowledge to recognition / reconstruction methods!

OAI 5g nr+usrp b210 installation and construction
![[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics](/img/2d/9a7e88fb774984d061538e3ad4a96b.png)
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics

Common English vocabulary that every programmer must master (recommended Collection)
随机推荐
Comprehensive evaluation and recommendation of the most comprehensive knowledge base management tools in the whole network: flowus, baklib, jiandaoyun, ones wiki, pingcode, seed, mebox, Yifang cloud,
js中,字符串和数组互转(一)——字符串转为数组的方法
This year, Jianzhi Tencent
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics
Study notes of grain Mall - phase I: Project Introduction
In JS, string and array are converted to each other (I) -- the method of converting string into array
el-table表格——sortable排序 & 出现小数、%时排序错乱
硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
What is the difference between procedural SQL and C language in defining variables
Yyds dry goods count re comb this of arrow function
【论文解读】用于白内障分级/分类的机器学习技术
for循环中break与continue的区别——break-完全结束循环 & continue-终止本次循环
3D人脸重建:从基础知识到识别/重建方法!
3D人脸重建:从基础知识到识别/重建方法!
#yyds干货盘点#重新梳理箭头函数的this
[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
防火墙基础之外网服务器区部署和双机热备
R语言可视化两个以上的分类(类别)变量之间的关系、使用vcd包中的Mosaic函数创建马赛克图( Mosaic plots)、分别可视化两个、三个、四个分类变量的关系的马赛克图
What are RDB and AOF
20220211 failure - maximum amount of data supported by mongodb