XV Open Cup named after E.V. Pankratiev. GP of Central Europe (AMPPZ-2014)--B.Petrol
多源最短路+并查集
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, k) for (int i = int(j); i <= int(k); ++ i)
typedef pair<int, int> P;
const int N = 2e5 + ;
const int inf = 2e9 + ;
vector<P> g[N];
int c[N], d[N], closest[N];
struct Query {
int x, y, b, ans, id;
void read() {
scanf("%d%d%d", &x, &y, &b);
}
}b[N];
struct triple {
int u, v, w;
};
int fa[N];
int findx(int x) {
if (x == fa[x]) return x;
return fa[x] = findx(fa[x]);
}
int main() {
int n, m, s;
scanf("%d%d%d", &n, &s, &m);
rep(i, , s) scanf("%d", &c[i]);
vector<triple> e;
rep(i, , m) {
int u, v, d;
scanf("%d%d%d", &u, &v, &d);
g[u].push_back(P(v, d));
g[v].push_back(P(u, d));
e.push_back((triple){u, v, d});
}
auto dijkstra = [&]() {
priority_queue<P, vector<P>, greater<P> > Q;
rep(i, , n) d[i] = inf;
rep(i, , s) {
d[c[i]] = ; closest[c[i]] = c[i];
Q.push(P(, c[i]));
}
while (!Q.empty()) {
P r = Q.top(); Q.pop();
int u = r.second;
if (d[u] < r.first) continue;
for (P p: g[u]) {
int v = p.first;
if (d[v] > d[u] + p.second) {
d[v] = d[u] + p.second;
closest[v] = closest[u];
Q.push(P(d[v], v));
}
}
}
};
dijkstra();
int q;
scanf("%d", &q);
rep(i, , q) b[i].read(), b[i].id = i;
auto calc = [&](triple &x) -> int{
return d[x.u] + d[x.v] + x.w;
};
sort(b + , b + + q, [&](Query &a, Query &b) {
return a.b < b.b;
});
sort(begin(e), end(e), [&](triple &a, triple &b) {
return calc(a) < calc(b);
});
rep(i, , n) fa[i] = i;
auto same = [&](int x, int y) -> bool {
x = findx(x); y = findx(y);
return x == y;
};
auto unite = [&](int x, int y) {
x = findx(x); y = findx(y);
fa[x] = y;
};
int l = ;
rep(i, , q) {
while (l < m && calc(e[l]) <= b[i].b) {
unite(e[l].u, e[l].v);
l ++;
}
if (same(b[i].x, b[i].y)) b[i].ans = ;
}
sort(b + , b + + q, [&](Query &a, Query &b) {
return a.id < b.id;
});
rep(i, , q) printf("%s\n", b[i].ans? "TAK": "NIE");
}
/*
6 4 5
1 5 2 6
1 3 1
2 3 2
3 4 3
4 5 5
6 4 5
4
1 2 4
2 6 9
1 5 9
6 5 8 */
XV Open Cup named after E.V. Pankratiev. GP of Central Europe (AMPPZ-2014)--B.Petrol的更多相关文章
- XV Open Cup named after E.V. Pankratiev. GP of Central Europe (AMPPZ-2014)--J.Cave
给你一棵树,现在有m个专家,每个专家计划从$a_i$走到$b_i$, 经过的距离不超过$d_i$,现在让你找一个点,使得所有专家的路途都能经过这个点 令$S_i$表示满足第i个专家的所有点,先检查1可 ...
- XV Open Cup named after E.V. Pankratiev. GP of Tatarstan
A. Survival Route 留坑. B. Dispersed parentheses $f[i][j][k]$表示长度为$i$,未匹配的左括号数为$j$,最多的未匹配左括号数为$k$的方案数. ...
- XV Open Cup named after E.V. Pankratiev. GP of America
A. Area of Effect 首先最优解中必有一个点在圆的边界上. 若半径就是$R$,则枚举一个点,然后把剩下的事件极角扫描即可,时间复杂度$O(m(n+m)\log(n+m))$. 否则圆必然 ...
- XV Open Cup named after E.V. Pankratiev. GP of Three Capitals
A. Add and Reverse 要么全部都选择$+1$,要么加出高$16$位后翻转位序然后再补充低$16$位. #include<stdio.h> #include<iostr ...
- XV Open Cup named after E.V. Pankratiev. GP of Siberia-Swimming
给出两个点,找到过这两个点的等角螺线,并求出中间的螺线长 $c = \frac{b}{a}$ $p = a \times c^{\frac{\theta}{angle}}$ 对弧线积分 #includ ...
- XII Open Cup named after E.V. Pankratiev. GP of Eastern Europe (AMPPZ-2012)
A. Automat $m$超过$1600$是没用的. 从后往前考虑,设$f[i][j][k]$表示考虑$[i,n]$这些物品,一共花费$j$元钱,买了$k$个物品的最大收益. 时间复杂度$O(n^5 ...
- XV Open Cup named after E.V. Pankratiev Stage 6, Grand Prix of Japan Problem J. Hyperrectangle
题目大意: 给出一个$d$维矩形,第i维的范围是$[0, l_i]$. 求满足$x_1 + x_2 + ...x_d \leq s$ 的点构成的单纯形体积. $d, l_i \leq 300$ 题解: ...
- XVI Open Cup named after E.V. Pankratiev. GP of Eurasia
A. Nanoassembly 首先用叉积判断是否在指定向量右侧,然后解出法线与给定直线的交点,再关于交点对称即可. #include<bits/stdc++.h> using names ...
- XVI Open Cup named after E.V. Pankratiev. GP of SPB
A. Bubbles 枚举两个点,求出垂直平分线与$x$轴的交点,答案=交点数+1. 时间复杂度$O(n^2\log n)$. #include<cstdio> #include<a ...
随机推荐
- eclipse jpa 工具生成实体类
1,配置数据库连接 打开eclipse, 选择数据库: 下一步,选择驱动包 根据自己的驱动包路径选择对应的驱动包: 2,配置jpa-tool 在项目上面右键->properties 点击ok,然 ...
- PHP提交失败保留填写后的信息
index.html: <html> <head> <title>jQuery Ajax 实例演示</title> </head> < ...
- day24--面向对象基础
要理解面向对象,我们首先要知道什么是面向过程 面向过程: 面向过程重点在过程两个字,神马是过程,这还要解释吗?我还是说下吧,过程就是一条线,一个步骤跟着一个步骤,更生动点的说就是像工厂里面的流水线一样 ...
- 去除菜单项的加速键--‘&’符号
去除菜单项的加速键--‘&’符号 ---------PopupMenu的AutoHotKeys(不用设置每个Item的这个属性)设置为maManual就行了
- MyBatis探究-----返回Map类型数据
1.使用@MapKey @MapKey:告诉mybatis封装Map的时候使用哪个属性作为Map的key Map<K, V>:键是这条记录的主键key,值是记录封装后的javaBean 1 ...
- 对接 第三方物流APP 手机版
昨天因为bibi项目要对接 物流信息 开始找了快递鸟文档,但是要填写申请APP,必须要注册公司才可以,这样非常麻烦.下面的第三方物理接口,绝对让你满意. https://m.kuaidi100.com ...
- 使用google earth engine根据NDWI(归一化水指数)提取水体信息
交流合作请联系: ab000c@163.com
- Linux代理服务器—squid正向代理实验
1.代理服务器squid简介 Squid cache(简称为Squid)是一个流行的自由软件(GNU通用公共许可证)的代理服务器和Web缓存服务器.Squid有广泛的用途,从作为网页服务器的前置cac ...
- 4.JAVA基础复习——JAVA中的构造函数与this关键字
构造函数:构建创造对象时调用的函数 特点: 1.函数名与类名相同. 2.不用定义返回值类型. 3.没有具体的返回值. public class Demo { private int age; priv ...
- 自制操作系统Antz(13) 显示图片
显示图片只是在多媒体课上看着bmp格式图片的突发奇想,然后就实现在了我自己的操作系统 Antz系统更新地址 Linux内核源码分析地址 Github项目地址 效果图: 显示图片的原理 在之前显卡操作时 ...