CSP--JT4奇妙85
  • 板块学术版
  • 楼主jr_linys
  • 当前回复10
  • 已保存回复10
  • 发布时间2023/10/21 20:38
  • 上次更新2023/11/2 12:09:33
查看原帖
CSP--JT4奇妙85
667763
jr_linys楼主2023/10/21 20:38

第 7−107-10 个点WA了,是 k=1k=1 的特殊点。

想不明白为什么会这样。

#include<bits/stdc++.h>
using namespace std;
int read(){
	char c;bool f=0;
	while(c=getchar(),c<'0'||c>'9') if(c=='-') f=1;
	int x=c^'0';
	while(c=getchar(),c>='0'&&c<='9') x=x*10+(c^'0');
	return f?-x:x;
}
const int N=10000,K=100;
int n,m,k;
int f[N+5][K+5];
bool vis[N+5][K+5];
vector<pair<int,int> > gr[N+5];
struct stu{
	int u,x,s;
	bool operator<(stu b)const{
		return s>b.s;
	}
};
priority_queue<stu> q;

int main(){
	freopen("bus.in","r",stdin);
	freopen("bus.out","w",stdout);
	n=read(),m=read(),k=read();
	for(int i=1,u;i<=m;++i) u=read(),gr[u].push_back({read(),read()});
	memset(f,127,sizeof f);
	f[1][0]=0;
	q.push({1,0,0});
	while(!q.empty()){
		int u=q.top().u,x=q.top().x,s=q.top().s+1;q.pop();
		if(vis[u][x]) continue;
		vis[u][x]=1,x=(x+1)%k;
		for(auto l:gr[u]){
			int ns=s;
			if(ns<l.second) ns+=((l.second-ns-1)/k+1)*k;
			if(ns<f[l.first][x]){
				f[l.first][x]=ns;
				q.push({l.first,x,ns});
			}
		}
	}
	if(f[n][0]==f[0][0]) printf("-1");
	else printf("%d",f[n][0]);
}
2023/10/21 20:38
加载中...