QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#735741#6306. Chase Gamedsbdsb#WA 0ms11392kbC++141.5kb2024-11-11 21:30:542024-11-11 21:30:55

Judging History

你现在查看的是最新测评结果

  • [2024-11-11 21:30:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11392kb
  • [2024-11-11 21:30:54]
  • 提交

answer

#include<bits/stdc++.h>
#define N 200010
#define ll long long
#define pli pair<ll,int>
#define fi first
#define se second
using namespace std;
int n,m,k,dn[N],dk[N];
ll d,dis[N];
vector<int> ve[N];
queue<int> q;
priority_queue<pli> pq;

inline ll solve(ll x){
	ll fz=x/d,g=x%d;
	ll ans=fz*(d+1)*d/2+g*(2*d-g+1)/2;
	return ans;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m>>k>>d;
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		ve[u].push_back(v);
		ve[v].push_back(u);
	}
	memset(dn,-1,sizeof dn);
	q.push(n);
	dn[n]=0;
//	printf("!!!\n");
	while(!q.empty()){
		int e=q.front();q.pop();
		for(auto i:ve[e]) if(dn[i]==-1){
			q.push(i);
			dn[i]=dn[e]+1;
		}
	}
	q.push(k);
	memset(dk,-1,sizeof dk);
	dk[k]=0;
	while(!q.empty()){
		int e=q.front();q.pop();
		for(auto i:ve[e]) if(dk[i]==-1){
			q.push(i);
			dk[i]=dk[e]+1;
		}
	}
	if(dk[1]>=d+1){
		cout<<solve(dn[1]);
		return 0;
	}
	int fl=0;
	for(auto i:ve[1]){
		if(dk[i]<d){
			pq.push({dk[i]-d,i});
		}
		else fl=1;
	}
	ll ans=1e18;
	memset(dis,-1,sizeof dis);
	dis[1]=0;
	while(!pq.empty()){
		pli e=pq.top();pq.pop();
		if(dis[e.se]!=-1) continue;
		dis[e.se]=-e.fi;
		if(dk[e.se]==d){
			ans=min(ans,solve(dn[e.se]+1)-e.fi);
			continue;
		}
		for(auto i:ve[e.se]){
			if(dis[i]!=-1) continue;
			pq.push({e.fi+dk[i]-d,i});
		}
	}
	if(dis[n]!=-1) ans=min(ans,dis[n]);
	if(fl) ans=min(ans,solve(dn[1]));
	cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 11392kb

input:

5 5 3 1
1 2
2 4
4 5
1 3
3 5

output:

1

result:

wrong answer 1st numbers differ - expected: '2', found: '1'