test

xxxx (hdu xxxx)

1. xxx

2. xxx

  • jkf
  • jksjd
  • jdks
  • kjdskl

  1. fd
  2. cxzc
  3. dfd
  4. fdfd
  5. fdsf
  6. fd
  7. fda
  8. fda
  9. hfhjdf
  10. fjkd
  11. fjdkljfdlk

fdfd
fdfd
fdfd

const int MAXN = 1005;//点的个数
const int INF = 0x3f3f3f3f;

inline int read()
{
	int now = 0; register char c = getchar();
	for (; !isdigit(c); c = getchar());
	for (; isdigit(c); now = now * 10 + c - '0', c = getchar());
	return now;
}

struct node
{
	int v;//点的编号
	int c;//距离
	node(int _v = 0, int _c = 0) :v(_v), c(_c) {}
	bool operator <(const node&r) const { return c < r.c; }
};

struct Edge
{
	int v;//到哪条边
	int cost;//距离
	Edge(int _v = 0, int _cost = 0) :v(_v), cost(_cost) {}
};

vector<Edge> E[MAXN];
bool vis[MAXN];
int dist[MAXN];

void Dijkstra(int n, int start)
{
	MS(vis);
	MS(dist);
	priority_queue<node>q;
	while (!q.empty()) q.pop();
	dist[start] = INF;
	q.push(node(start, 0));
	node temp;
	while (!q.empty())
	{
		temp = q.top();
		q.pop();
		int u = temp.v;
		if (vis[u]) continue;
		vis[u] = true;
		for (int i = 0; i < E[u].size(); i++)
		{
			int v = E[u][i].v;
			int cost = E[u][i].cost;
			if (!vis[v] && dist[v] < min(dist[u], cost))
			{
				dist[v] = min(dist[u], cost);
				q.push(node(v, dist[v]));
			}
		}
	}
}

void addEdge(int u, int v, int w)
{
	E[u].push_back(Edge(v, w));
}

int main()
{
	int CASE = 1;
	for (int T = read(); T; T--)
	{
		int n = read(), m = read();
		for (int i = 1; i <= n; i++) E[i].clear();
		for (int i = 1; i <= m; i++)
		{
			int u = read(), v = read(), w = read();
			addEdge(u, v, w);
			addEdge(v, u, w);
		}
		Dijkstra(n, 1);
		printf("Scenario #%d:\n%d\n\n", CASE++, dist[n]);
	}
}

o(N)
O ( n ) O(n) O(n)
s s \frac {s}{s} ss
∀ \forall
∑ i = 0 N \sum^{N}_{i=0} i=0N

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值