P9751 [CSP-J 2023] 旅游巴士
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 Commute61.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 int long long
#define double long double
#define lowbit(x) ((x)&(-x))
const int inf=1e18;
const int mod=1e9+7;
const int N=4e5;
int qpow(int a,int n)
{
int res=1;
while(n)
{
if(n&1) res=res*a%mod;
a=a*a%mod;
n>>=1;
}
return res;
}
int inv(int x)
{
return qpow(x,mod-2);
}
int fa[2000005];
int finds(int now){return now==fa[now]?now:finds(fa[now]);}
vector<int> G[200005];
int dfn[200005],low[200005];
int cnt=0,num=0;
int in_st[200005]={0};
stack<int> st;
int belong[200005]={0};
void scc(int now,int fa)
{
dfn[now]=++cnt;
low[now]=dfn[now];
in_st[now]=1;
st.push(now);
for(auto next:G[now])
{
if(next==fa) continue;
if(!dfn[next])
{
scc(next,now);
low[now]=min(low[now],low[next]);
}
else if(in_st[next])
{
low[now]=min(low[now],dfn[next]);
}
}
if(low[now]==dfn[now])
{
int x;
num++;
do
{
x=st.top();
st.pop();
in_st[x]=0;
belong[x]=num;
}while(x!=now);
}
}
vector<int> prime;
bool mark[200005]={0};
void shai()
{
for(int i=2;i<=200000;i++)
{
if(!mark[i]) prime.push_back(i);
for(auto it:prime)
{
if(it*i>200000) break;
mark[it*i]=1;
if(it%i==0) break;
}
}
}
*/
struct node
{
int to,cost;
};
vector<node> G[10004];
struct fresh
{
int place,mod,t;
bool operator<(const fresh&c)const
{
return c.t<t;
}
};
int dis[10005][105];
void solve()
{
memset(dis,0x3f,sizeof dis);
int n,m,k;
cin>>n>>m>>k;
for(int i=1;i<=m;i++)
{
int x,y,t;
cin>>x>>y>>t;
G[x].push_back({y,t});
}
priority_queue<fresh> q;
q.push({1,0,0});
while(q.size())
{
auto [now,mod,t]=q.top();
q.pop();
if(dis[now][mod]<=t) continue;
dis[now][mod]=t;
for(auto next:G[now])
{
auto [to,wait]=next;
if(wait<=t)
{
q.push({to,(mod+1)%k,t+1});
}
else
{
int add=(wait-t)/k+((wait-t)%k!=0);
q.push({to,(mod+1)%k,t+add*k+1});
}
}
}
if(dis[n][0]>1e9) cout<<-1;
else cout<<dis[n][0];
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int TT=1;
//cin>>TT;
while(TT--) solve();
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搭建本