社区讨论
20分3~10WA,铅条
P4467[SCOI2007] k短路参与者 2已保存回复 6
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 6 条
- 当前快照
- 1 份
- 快照标识符
- @mhjcw4zc
- 此快照首次捕获于
- 2025/11/04 00:30 4 个月前
- 此快照最后确认于
- 2025/11/04 00:30 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
int n,m,k,a,b,i,j,u,v,w,h1[60],rh[60],cnt,cs[60];
long long dis[60];
bool wh[60];
struct node{
int id;
long long ddd;
string lu;
friend bool operator <(const node &lhy1,const node &lhy2){
if(lhy1.ddd>lhy2.ddd) return 1;
if(lhy1.ddd==lhy2.ddd&&lhy1.lu>lhy2.lu) return 1;
return 1;
}
};
struct bian{
int to,ne,sss;
}edge[2000010];
void ad(int x[],int start1,int end1,int weight){
edge[++cnt].ne=x[start1];
edge[cnt].sss=weight;
edge[cnt].to=end1;
x[start1]=cnt;
}
void djstl(){
priority_queue<node> jl;
node st;
st.id=b,st.ddd=0,st.lu="";
jl.push(st);
while(!jl.empty()){
node tt=jl.top();
jl.pop();
int now=tt.id;
if(wh[now]==1) continue;
wh[now]=1;
for(int p=rh[now];p!=0;p=edge[p].ne){
int mdd=edge[p].to;
if(dis[mdd]>dis[now]+edge[p].sss){
dis[mdd]=dis[now]+edge[p].sss;
int le=st.lu.size(),zjl=mdd;
string cj="";
if(zjl<=9){
cj+=(zjl+'0');
cj+='-';
}
else{
cj+=(zjl/10)+'0';
cj+=(zjl%10)+'0';
cj+='-';
}
cj=cj+st.lu;
jl.push({mdd,dis[mdd],cj});
}
}
}
return ;
}
struct nod{
long long ma;
int dq;
long long yz;
string ll;
bool vis[60];
friend bool operator <(const nod &mm1,const nod &mm2){
if(mm1.ma>mm2.ma) return 1;
if(mm1.ma==mm2.ma&&mm1.ll>mm2.ll) return 1;
return 0;
}
};
nod astar(){
priority_queue<nod> wzm;
nod hzy;
hzy.ma=dis[a];
hzy.dq=a;
hzy.yz=0;
hzy.ll="";
hzy.vis[a]=1;
if(a<=9){
hzy.ll+=a+'0';
}
else{
hzy.ll+=(a/10)+'0';
hzy.ll+=(a%10)+'0';
}
wzm.push(hzy);
while(!wzm.empty()){
nod tt=wzm.top();
wzm.pop();
int now=tt.dq;
long long mei=tt.yz;
string wc=tt.ll;
cs[now]++;
if(cs[b]==k){
return tt;
}
for(int sym=h1[now];sym!=0;sym=edge[sym].ne){
int xyg=edge[sym].to;
if(cs[xyg]<k&&tt.vis[xyg]==0){
string zj="";
if(xyg<=9){
if(wc!="") zj+='-';
zj+=(xyg+'0');
}
else{
if(wc!="") zj+='-';
zj+=((xyg/10)+'0');
zj+=((xyg%10)+'0');
}
zj=wc+zj;
bool chr[60];
for(int wsm=1;wsm<=n;wsm++){
chr[wsm]=tt.vis[wsm];
}
chr[xyg]=1;
nod hdx={mei+dis[xyg]+edge[sym].sss,xyg,mei+edge[sym].sss,zj,chr[60]};
wzm.push(hdx);
}
}
}
nod bky={-1,-1,-1,"",};
return bky;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>k>>a>>b;
for(i=1;i<=n;i++){
dis[i]=200000000;
}
dis[b]=0;
for(i=1;i<=m;i++){
cin>>u>>v>>w;
ad(h1,u,v,w);
ad(rh,v,u,w);
}
djstl();
nod ans=astar();
if(ans.ma==-1) cout<<"No";
else cout<<ans.ll << '\n';
return 0;
}
回复
共 6 条回复,欢迎继续交流。
正在加载回复...