QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661009#6306. Chase GameFluoresceWA 1ms9064kbC++202.4kb2024-10-20 14:17:442024-10-20 14:17:45

Judging History

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

  • [2024-10-20 14:17:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9064kb
  • [2024-10-20 14:17:44]
  • 提交

answer

#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define debug(a) cout<<a<<'\n'
#define Pll pair<ll,ll>
#define PII pair<int,int>
#define ft first
#define sd second
#define vec vector
#define pushk push_back
#define ump unordered_map
#define pl p<<1
#define pr p<<1|1
using namespace std;
const int N = 1e5 + 10, M = 4e5 + 10, mod = 1e9 + 7;
const ll inf = 1e18;
const ld eps = 1e-13;
int mov[4][2] = { {0,1},{1,0},{-1,0},{0,-1} }, dx, dy, _ = 1, __ = 1;
void bout(bool f) {
	if (f)cout << "Yes\n";
	else cout << "No\n";
}
ll n, m, k,d;
int h[N],e[M],ne[M],idx;
void link(int x,int y){
	e[++idx]=y;
	ne[idx]=h[x];
	h[x]=idx;
}

ll dt[N],ds[N],dk[N];

void dij(ll d[],int u){
	memset(d,0x3f,sizeof dt);
	d[u]=0;
	ll dist,id;
	priority_queue<Pll,vector<Pll>,greater<Pll>>q;
	q.push({0,u});
	while(!q.empty()){
		dist=q.top().ft;
		id=q.top().sd;
		q.pop();
		if(d[id]<dist)continue;
		for(int i=h[id];~i;i=ne[i]){
			int v=e[i];
			if(d[v]>d[id]+1){
				d[v]=d[id]+1;
				q.push({d[v],v});
			}
		}
	}
}

ll cul(int dist){
	ll x,y;
	x=dist/d*d*(d+1)/2;
	y=dist%d;
	return x+y*(2*d-y+1)/2;
}

void ini() {

}
void solve() {
	cin>>n>>m>>k>>d;
	memset(h,-1,sizeof h);idx=0;
	ll x,y,z;
	for(int i=1;i<=m;++i){
		cin>>x>>y;
		link(x,y);
		link(y,x);
	}
	dij(dt,n);
	dij(dk,k);
	ll ans=cul(dt[1]);
	if(dk[1]>d)cout<<dt[1];
	else{
		memset(ds,0x3f,sizeof ds);
		ds[1]=0;
		priority_queue<Pll,vec<Pll>,greater<Pll>>q;
		q.push({0,1});
		ll dist,u;
		while(!q.empty()){
			dist=q.top().ft;
			u=q.top().sd;
			q.pop();
			if(dist>ds[u])continue;
			for(int i=h[u];~i;i=ne[i]){
				int v=e[i];
				x=d-dk[v];
				if(x>=1){
					if(ds[v]>ds[u]+x){
						ds[v]=ds[u]+x;
						q.push({ds[v],v});
					}
				}else if(x==0&&(dk[1]!=d||u!=1)){
					if(ds[v]>ds[u])ds[v]=ds[u];//外圈 
				}
			}
		}
		for(int i=1;i<=n;++i){
			if(dk[i]==d){
				ans=min(ans,ds[i]+cul(dt[i]+1));
			}
		}
		if(dk[n]<d)ans=min(ans,ds[n]);
	}
	cout<<ans;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	streambuf* cinbackup = cin.rdbuf(), * coutbackup = cout.rdbuf();
	ifstream fin("in.txt");
	ofstream fout("out.txt");
	cin.rdbuf(fin.rdbuf());
	cout.rdbuf(fout.rdbuf());
#endif
	//cin >> _;
	__ = _;
	ini();
	while (_--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 8104kb

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 9064kb

input:

13 17 12 3
1 2
2 3
3 4
4 13
5 13
7 8
7 9
7 10
7 11
7 6
12 7
1 8
8 9
9 10
10 11
11 6
6 13

output:

7

result:

ok 1 number(s): "7"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 8640kb

input:

10 9 4 1
4 3
1 2
7 6
6 5
8 9
9 10
5 4
8 7
3 2

output:

99

result:

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