QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#297567 | #6306. Chase Game | yokeff# | WA | 1ms | 8124kb | C++17 | 1.3kb | 2024-01-04 19:06:38 | 2024-01-04 19:06:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> e[100000+10];
int dis[100000+10];
int dis1[100000+10];
int dis2[100000+10];
signed main (){
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m,k,d;
cin>>n>>m>>k>>d;
memset(dis1,0x3f,sizeof(dis1));
dis1[1] =0;
for(int i=1;i<=m;i++)
{
int u,v;
cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
}
queue<int> q;
q.push(n);
dis2[n] = 1;
while(!q.empty())
{
auto x=q.front();
q.pop();
for(auto v:e[x])
{
if(dis2[v])
continue ;
else
dis2[v] = dis2[x] +1;
q.push(v);
}
}
q.push(k);
dis[k] = 1;
while(!q.empty())
{
auto x=q.front();
q.pop();
for(auto v:e[x])
{
if(dis[v])
continue ;
else
dis[v] = dis[x] +1;
q.push(v);
}
}
q.push(1);
int ans = LLONG_MAX;
while(!q.empty())
{ auto x = q.front();
q.pop();
for(auto v:e[x])
{
if(dis[v]>d)
{
int sub = (dis2[v]-1)%d;
ans = min(ans,dis1[v]+(dis2[v]-1)/d*(d*(d+1))/2+sub*(sub+1)/2);
}
else if(v==n)
{
ans = min(ans,dis1[x]+(d-dis[v]+1));
}
else if(dis1[v]>dis1[x]+(d-dis[v]))
{
dis1[v] = dis1[x]+(d-dis[v]+1);
q.push(v);
}
}
}
cout<<ans<<endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 8124kb
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: 8116kb
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: 7604kb
input:
10 9 4 1 4 3 1 2 7 6 6 5 8 9 9 10 5 4 8 7 3 2
output:
4557430888798830407
result:
wrong answer 1st numbers differ - expected: '9', found: '4557430888798830407'