社区讨论
求问(有思路,赛时 10 分)
P14318「ALFR Round 11」B 行走 (walk)参与者 7已保存回复 6
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 6 条
- 当前快照
- 1 份
- 快照标识符
- @mhizyn1d
- 此快照首次捕获于
- 2025/11/03 18:28 4 个月前
- 此快照最后确认于
- 2025/11/03 18:28 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int,int>;
#define int LL
const int N = 1e5 + 5;
int n, m, k, vis[N];
vector<int> G[N];
inline void read(int& a) {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
ch = getchar();
}
a = s * w;
}
int splen(int s, int e){
for(int i = 1; i <= n; ++ i)
vis[i] = 0;
vis[s] = 1;
queue<int> q;
q.push(s);
int tot = 0;
while(!q.empty()){
int siz = q.size();
for(int i = 1; i <= siz; ++ i){
int u = q.front();
// cout << "tot=" << tot << ",visit " << u << "\n";
q.pop();
for(int v: G[u]){
// cout<<"zijiedian:"<<v<<"\n";
if(v == e){//cout<<"found "<<v<<"\n";
return tot + 1;}
if(!vis[v])
vis[v] = 1, q.push(v);
}
}
++ tot;
// cout<<"tot="<<tot<<" start__________\n";
}
return -1;
}
signed main(){
int t;
read(t);
while(t --){
read(n),read(m),read(k);
for(int i = 1; i <= n; ++ i)
G[i].clear();
// cout << "n="<<n<<" m="<<m<<" k="<<k;
for(int i = 1, u, v; i <= m; ++ i)
read(u),read(v), G[u].push_back(v), G[v].push_back(u);
int as, ae, bs, be;
read(as),read(ae),read(bs),read(be);
// cout << "cin ended\n";
int r1 = splen(as, ae), r2 = splen(bs, be);
if(r1 == -1 || r2 == -1){
cout << -1;
continue;
}
int tote = r1 + r2;
// cout << r1 << " " << r2 << "\n";
int t = k / tote;
long double ans = 0.0;
ans += tote * (1.0 / (t + 1)) + (k % tote) * (1.0 / (t + 2) - 1.0 / (t + 1));
printf("%.12Lf\n",ans);
}
}
有人能帮忙看一下这段代码为什么赛时 10pts 吗,已有思路,谢谢。
回复
共 6 条回复,欢迎继续交流。
正在加载回复...