POJ1847 Tram

                  Tram
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 20274 Accepted: 7553

Description

Tram network in Zagreb consists of a number of intersections and rails connecting some of them. In every intersection there is a switch pointing to the one of the rails going out of the intersection. When the tram enters the intersection it can leave only in the direction the switch is pointing. If the driver wants to go some other way, he/she has to manually change the switch.

When a driver has do drive from intersection A to the intersection B he/she tries to choose the route that will minimize the number of times he/she will have to change the switches manually.

Write a program that will calculate the minimal number of switch changes necessary to travel from intersection A to intersection B.

Input

The first line of the input contains integers N, A and B, separated by a single blank character, 2 <= N <= 100, 1 <= A, B <= N, N is the number of intersections in the network, and intersections are numbered from 1 to N.

Each of the following N lines contain a sequence of integers separated by a single blank character. First number in the i-th line, Ki (0 <= Ki <= N-1), represents the number of rails going out of the i-th intersection. Next Ki numbers represents the intersections directly connected to the i-th intersection.Switch in the i-th intersection is initially pointing in the direction of the first intersection listed.

Output

The first and only line of the output should contain the target minimal number. If there is no route from A to B the line should contain the integer "-1".

Sample Input

3 2 1
2 2 3
2 3 1
2 1 2

Sample Output

0

Dijkstra+堆优化,比较简单的一道题。

说一下思路吧:
每个节点与所有可到达节点之间连边,与初始指向节点的权值为0,与其余可到达的节点的权值为1。
然后求最短路。

#include <cstdio>
#include <queue>
using namespace std;

inline int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0' || c>'9'){if (c=='-')f=-1;c=getchar();}
	while (c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-48;c=getchar();}
	return x*f;
}

inline void print(int x)
{
	if (x<0)x=-x,putchar('-');
	if (x>9)print(x/10);
	putchar(x%10+48);
}

inline void print(int x,char c)
{
	print(x);
	putchar(c);
}

const int INF=10000000;
const int MAXN=101;
int n,from,to;
int a[MAXN];
int cost[MAXN][MAXN];

struct dij
{
	int id,dis;
	bool operator < (const dij tmp) const
	{
		return dis>tmp.dis;
	}
};
int dis[MAXN];

inline void dijkstra()
{
	int u;
	for (int i=1;i<=n;i++)dis[i]=INF;
	dis[from]=0;
	priority_queue<dij> Q;
	Q.push((dij){from,0});
	while (!Q.empty())
	{
		u=Q.top().id;Q.pop();
		for (int i=1;i<=n;i++)
			if (dis[u]+cost[u][i]<dis[i])
			{
				dis[i]=dis[u]+cost[u][i];
				Q.push((dij){i,dis[i]});
			}
	}
}

int main()
{
	n=read();from=read();to=read();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			cost[i][j]=INF;
	for (int i=1;i<=n;i++)cost[i][i]=0;
	int top,k;
	for (int i=1;i<=n;i++)
	{
		top=read();
		if (!top)continue;
		cost[i][read()]=0;
		for (int j=2;j<=top;j++)cost[i][read()]=1;
	}
	dijkstra();
	if (dis[to]<INF)print(dis[to],'\n');
	else print(-1,'\n');
	return 0;
}

 

转载于:https://www.cnblogs.com/lzxzy-blog/p/10501833.html

内容概要:文章介绍了DeepSeek在国内智能问数(smart querying over data)领域的实战应用。DeepSeek是一款国内研发的开源大语言模型(LLM),具备强大的中文理解、推理和生成能力,尤其适用于企业中文环境下的智能问答、知识检索等。它具有数据可控性强的特点,可以自部署、私有化,支持结合企业内部数据打造定制化智能问数系统。智能问数是指用户通过自然语言提问,系统基于结构化或非结构化数据自动生成精准答案。DeepSeek在此过程中负责问题理解、查询生成、多轮对话和答案解释等核心环节。文章还详细展示了从问题理解、查询生成到答案生成的具体步骤,并介绍了关键技术如RAG、Schema-aware prompt等的应用。最后,文章通过多个行业案例说明了DeepSeek的实际应用效果,显著降低了数据使用的门槛。 适合人群:从事数据分析、企业信息化建设的相关从业人员,尤其是对智能化数据处理感兴趣的业务和技术人员。 使用场景及目标:①帮助业务人员通过自然语言直接获取数据洞察;②降低传统BI工具的操作难度,提高数据分析效率;③为技术团队提供智能问数系统的架构设计和技术实现参考。 阅读建议:此资源不仅涵盖了DeepSeek的技术细节,还提供了丰富的实战案例,建议读者结合自身业务场景,重点关注DeepSeek在不同行业的应用方式及其带来的价值。对于希望深入了解技术实现的读者,可以进一步探索Prompt工程、RAG接入等方面的内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值