Choose the best route

本文探讨了在一个具有多个公交站点的城市中,寻找从一组起始站点到特定目标站点的最短时间路径的问题。通过使用图论和动态规划,文章提供了一个有效的算法实现,能够处理大量的站点和路线。

题目:

One day , Kiki wants to visit one of her friends. As she is liable to carsickness , she wants to arrive at her friend’s home as soon as possible . Now give you a map of the city’s traffic route, and the stations which are near Kiki’s home so that she can take. You may suppose Kiki can change the bus at any station. Please find out the least time Kiki needs to spend. To make it easy, if the city have n bus stations ,the stations will been expressed as an integer 1,2,3…n.

Input

There are several test cases.
Each case begins with three integers n, m and s,(n<1000,m<20000,1=<s<=n) n stands for the number of bus stations in this city and m stands for the number of directed ways between bus stations .(Maybe there are several ways between two bus stations .) s stands for the bus station that near Kiki’s friend’s home.
Then follow m lines ,each line contains three integers p , q , t (0<t<=1000). means from station p to station q there is a way and it will costs t minutes .
Then a line with an integer w(0<w<n), means the number of stations Kiki can take at the beginning. Then follows w integers stands for these stations.

Output

The output contains one line for each data set : the least time Kiki needs to spend ,if it’s impossible to find such a route ,just output “-1”.

Sample Input

5 8 5
1 2 2
1 5 3
1 3 4
2 4 7
2 5 6
2 3 5
3 5 1
4 5 1
2
2 3
4 3 4
1 2 3
1 3 4
2 3 2
1
1

Sample Output

1
-1

类似于一个人的旅行,不同的是该题是单向边,而且端点为1-n;

代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int inf=100000;
int dis[1005];
int e[1005][1005];
bool book[1005];
int n,m;
void intt()
{
    memset(book,0,sizeof(book));
    for(int i=0;i<=n;i++)
        dis[i]=inf;
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
            {
                if(i==j) e[i][j]=0;
                else e[i][j]=inf;
            }
}
int main()
{
    int t1,t2,t3;
    int st,en;
    while(scanf("%d %d %d",&n,&m,&en)!=EOF)
    {
        intt();
        int a;
        for(int i=0;i<m;i++)
        {
            scanf("%d %d %d",&t1,&t2,&t3);
            e[t1][t2]=min(e[t1][t2],t3);
        }
        int b;
        scanf("%d",&a);
        for(int i=0;i<a;i++)
        {
            scanf("%d",&b);
            e[0][b]=0;
        }
        for(int i=0;i<=n;i++)
            dis[i]=e[0][i];
        book[0]=1;
        dis[0]=0;
        for(int i=0;i<=n;i++)
        {
            int minn=inf;
            int u;
            for(int j=0;j<=n;j++)
            {
                if(book[j]==0&&dis[j]<minn)
                {
                    u=j;
                    minn=dis[j];
                }
            }
            book[u]=1;
            for(int v=0;v<=n;v++)
            {
                if(e[u][v]<inf)
                {
                    if(dis[v]>dis[u]+e[u][v])
                        dis[v]=dis[u]+e[u][v];
                }
            }
        }
        if(dis[en]!=inf)
            printf("%d\n",dis[en]);
        else
            printf("-1\n");
    }
    return 0;
}
 

FIB sources There are various entities in the system that can add routes to the FIB tables. Each of these entities is termed a source. When the same prefix is added by different sources the FIB must arbitrate between them to determine which source will contribute the forwarding information. Since each source determines the forwarding information using different best path and loop prevention algorithms, it is not correct for the forwarding information of multiple sources to be combined. Instead the FIB must choose to use the forwarding information from only one source. This choice is based on a static priority assignment 4. The FIB must maintain the information each source has added so it can be restored should that source become the best source. VPP has two control-plane sources; the API and the CLI the API has the higher priority. Each source data is represented by a fib_entry_src_t object of which a fib_entry_t maintains a sorted vector. The following configuration: set interface ip address GigabitEthernet0/8/0 192.168.1.1/24 results in the addition of two FIB entries; 192.168.1.0/24 which is connected and attached, and 192.168.1.1/32 which is connected and local (a.k.a. receive or for-us). A prefix is connected when it is applied to a router’s interface. Both prefixes are interface sourced. The interface source has a high priority, so the accidental or nefarious addition of identical prefixes does not prevent the router from correctly forwarding. Packets matching a connected prefix will generate an ARP request for the packets destination address, this process is known as a glean. An attached prefix also results in a glean, but the router does not have its own address in that sub-net. The following configuration will result in an attached route, which resolves via an attached path; ip route add table X 10.10.10.0/24 via gre0 as mentioned before, these are only appropriate for point-to-point links. If table X is not the table to which gre0 is bound, then this is the case of an attached export (see the section Attached Export). Adjacency source FIB entries Whenever an ARP entry is created it will source a fib_entry_t. In this case the route is of the form: ip route add table X 10.0.0.1/32 via 10.0.0.1 GigabitEthernet0/8/0 This is a host prefix with a path whose next-hop address is the same host. This route highlights the distinction between the route’s prefix - a description of the traffic to match - and the path - a description of where to send the matched traffic. Table X is the same table to which the interface is bound. FIB entries that are sourced by adjacencies are termed adj-fibs. The priority of the adjacency source is lower than the API source, so the following configuration: set interface address 192.168.1.1/24 GigabitEthernet0/8/0 ip arp 192.168.1.2 GigabitEthernet0/8/0 dead.dead.dead ip route add 192.168.1.2 via 10.10.10.10 GigabitEthernet1/8/0 will forward traffic for 192.168.1.2 via GigabitEthernet1/8/0. That is the route added by the control plane is favoured over the adjacency discovered by ARP. The control plane, with its associated authentication, is considered the authoritative source. To counter the nefarious addition of adj-fibs, through the nefarious injection of adjacencies, the FIB is also required to ensure that only adj-fibs whose less specific covering prefix is attached are installed in forwarding. This requires the use of cover tracking, where a route maintains a dependency relationship with the route that is its less specific cover. When this cover changes (i.e. there is a new covering route) or the forwarding information of the cover is updated, then the covered route is notified. Adj-fibs that fail this cover check are not installed in the fib_table_t’s forwarding table, they are only present in the non-forwarding table. Overlapping sub-nets are not supported, so no adj-fib has multiple paths. The control plane is expected to remove a prefix configured for an interface before the interface changes VRF.翻译一下
10-23
内容概要:本文详细介绍了“秒杀商城”微服务架构的设计与实战全过程,涵盖系统从需求分析、服务拆分、技术选型到核心功能开发、分布式事务处理、容器化部署及监控链路追踪的完整流程。重点解决了高并发场景下的超卖问题,采用Redis预减库存、消息队列削峰、数据库乐观锁等手段保障数据一致性,并通过Nacos实现服务注册发现与配置管理,利用Seata处理跨服务分布式事务,结合RabbitMQ实现异步下单,提升系统吞吐能力。同时,项目支持Docker Compose快速部署和Kubernetes生产级编排,集成Sleuth+Zipkin链路追踪与Prometheus+Grafana监控体系,构建可观测性强的微服务系统。; 适合人群:具备Java基础和Spring Boot开发经验,熟悉微服务基本概念的中高级研发人员,尤其是希望深入理解高并发系统设计、分布式事务、服务治理等核心技术的开发者;适合工作2-5年、有志于转型微服务或提升架构能力的工程师; 使用场景及目标:①学习如何基于Spring Cloud Alibaba构建完整的微服务项目;②掌握秒杀场景下高并发、超卖控制、异步化、削峰填谷等关键技术方案;③实践分布式事务(Seata)、服务熔断降级、链路追踪、统一配置中心等企业级中间件的应用;④完成从本地开发到容器化部署的全流程落地; 阅读建议:建议按照文档提供的七个阶段循序渐进地动手实践,重点关注秒杀流程设计、服务间通信机制、分布式事务实现和系统性能优化部分,结合代码调试与监控工具深入理解各组件协作原理,真正掌握高并发微服务系统的构建能力。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值