P8724 [蓝桥杯 2020 省 AB3] 限高杆
1.F. Chat Screenshots2.P1656 炸铁路3.P1137 旅行计划4.P2835 刻录光盘5.P1197 [JSOI2008] 星球大战6.P3388 【模板】割点(割顶)7.P8435 【模板】点双连通分量8.P8436 【模板】边双连通分量9.P2860 [USACO06JAN] Redundant Paths G10.P1653 [USACO04DEC] Cow Ski Area G11.P3047 [USACO12FEB] Nearby Cows G12.P1894 [USACO4.2] 完美的牛栏The Perfect Stall13.P1550 [USACO08OCT] Watering Hole G14.P2330 [SCOI2005] 繁忙的都市15.P1525 [NOIP2010 提高组] 关押罪犯16.P1379 八数码难题17.P2746 [USACO5.3] 校园网Network of Schools18.P6121 [USACO16OPEN] Closing the Farm G19.P2341 [USACO03FALL / HAOI2006] 受欢迎的牛 G20.P2055 [ZJOI2009] 假期的宿舍21.P5905 【模板】全源最短路(Johnson)22.F. Microcycle23.G. Path Prefixes24.G. Rudolf and Subway25.C. Ehab and Path-etic MEXs26.A. String Transformation 127.D. Secret Passwords28.F. Maximum White Subtree29.P3478 [POI2008] STA-Station30.P1347 排序31.P1960 郁闷的记者32.E1. Weights Division (easy version)33.P5007 DDOSvoid 的疑惑34.P2850 [USACO06DEC] Wormholes G35.P1265 公路修建36.P1354 房间最短路问题37.P2168 [NOI2015] 荷马史诗38.P8306 【模板】字典树39.P1481 魔族密码40.P3128 [USACO15DEC] Max Flow P41.P5536 【XR-3】核心城市42.P5836 [USACO19DEC] Milk Visits S43.P3384 【模板】重链剖分/树链剖分44.P5960 【模板】差分约束45.P7771 【模板】欧拉路径46.六度分离47.整数区间48.F. Alex's whims49.J. 上学50.Game on Tree51.E. We Need More Bosses52.B. Omkar and Heavenly Tree53.B. Mahmoud and Ehab and the bipartiteness54.P1668 [USACO04DEC] Cleaning Shifts S55.P6154 游走56.P8655 [蓝桥杯 2017 国 B] 发现环57.P10298 [CCC 2024 S4] Painting Roads58.P9650 [SNCPC2019] Escape Plan59.P9327 [CCC 2023 S4] Minimum Cost Roads60.P9026 [CCC2021 S4] Daily Commute
61.P8724 [蓝桥杯 2020 省 AB3] 限高杆
62.P4878 [USACO05DEC] Layout G63.P5663 [CSP-J2019] 加工零件64.P2731 [USACO3.3] 骑马修栅栏 Riding the Fences65.I. Disks66.P1351 [NOIP2014 提高组] 联合权值67.B. Time Travel68.F. Minimum Maximum Distance69.A. Book70.P1407 [国家集训队] 稳定婚姻71.P1991 无线通讯网72.P4047 [JSOI2010] 部落划分73.P3275 [SCOI2011] 糖果74.P1989 无向图三元环计数75.P1967 [NOIP2013 提高组] 货车运输76.D. Vitaly and Cycle77.P10838 『FLA - I』庭中有奇树78.P9751 [CSP-J 2023] 旅游巴士79.D. Colored Portals题解
分层图,太奥妙了
每层图都是一样的
code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline void read(ll &x) {
x = 0;
ll flag = 1;
char c = getchar();
while(c < '0' || c > '9'){
if(c == '-')flag = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
x *= flag;
}
inline void write(ll x)
{
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
struct node
{
ll to, len;
};
vector<node> G[30015];
struct unit
{
ll x, y, w;
};
struct fresh
{
ll pos, val;
bool operator<(const fresh &b)const
{
return val > b.val;
}
};
ll dis[30015];
int main()
{
memset(dis, 0x3f, sizeof dis);
ll n, m;
read(n);
read(m);
for(ll i = 1; i <= m; i++)
{
ll x, y, w, c;
read(x);
read(y);
read(w);
read(c);
if(c)
{
G[x].push_back({y+n, w});
G[x+n].push_back({y+2*n, w});
G[y].push_back({x+n, w});
G[y+n].push_back({x+2*n, w});
continue;
}
G[x].push_back({y, w});
G[y].push_back({x, w});
G[x+n].push_back({y+n, w});
G[y+n].push_back({x+n, w});
G[x+2*n].push_back({y+2*n, w});
G[y+2*n].push_back({x+2*n, w});
}
priority_queue<fresh> q;
q.push({1, 0});
while(q.size())
{
ll now = q.top().pos, val = q.top().val;
q.pop();
if(dis[now] <= val) continue;
dis[now] = val;
for(auto next: G[now])
{
ll to = next.to, len = next.len;
if(dis[to] > dis[now] + len)
{
q.push({to, dis[now] + len});
}
}
}
// for(ll i = 1; i <= 3 * n; i++) cout << dis[i] << " ";
write(dis[n] - min(dis[2*n], dis[3*n]));
return 0;
}
合集:
图论
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本