比赛 |
4043级NOIP2022欢乐赛4th |
评测结果 |
AWA |
题目名称 |
路由选择问题 |
最终得分 |
66 |
用户昵称 |
op_组撒头屯 |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2022-11-07 20:02:37 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N=50+5;
struct sdf{
int to,w,next;
}eg[2*N*N];
int head[N],ne=0;
int n,p,s,t;
bool no[N]={0};
void add(int x,int y,int w){
eg[++ne]={y,w,head[x]};
head[x]=ne;return ;
}
struct wer{
int to,d;
bool operator<(const wer&x)const{
return d>x.d;
}
};
priority_queue<wer>q;
int dis[N],cdis[N];
bool vis[N]={0};
void dij1(){
memset(dis,0x3f,sizeof(dis));
dis[s]=0;q.push({s,0});
while(!q.empty()){
wer u=q.top();q.pop();
if (vis[u.to])continue;
vis[u.to]=1;
for (int i=head[u.to];i!=0;i=eg[i].next){
int v=eg[i].to,w=eg[i].w;
if (no[v])continue;
if (w+u.d<dis[v]){
dis[v]=w+u.d;
q.push({v,dis[v]});
}
}
}
printf("%d ",dis[t]);
return ;
}
void dij2(){
memset(dis,0x3f,sizeof(dis));
memset(cdis,0x3f,sizeof(cdis));
dis[s]=0;q.push({s,0});
while(!q.empty()){
wer u=q.top();q.pop();
if (u.d>cdis[u.to])continue;
for (int i=head[u.to];i!=0;i=eg[i].next){
int v=eg[i].to,w=eg[i].w;
if (u.d+w<dis[v]){
cdis[v]=dis[v];
dis[v]=u.d+w;
q.push({v,dis[v]});
q.push({v,cdis[v]});
}
else if (u.d+w<cdis[v]){
cdis[v]=u.d+w;
q.push({v,cdis[v]});
}
}
}
printf("%d %d\n",dis[t],cdis[t]);
return ;
}
int main(){
freopen ("route.in","r",stdin);
freopen ("route.out","w",stdout);
scanf("%d%d%d",&n,&s,&t);
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++){
int x;scanf("%d",&x);
if (x)add(i,j,x);
}
}
scanf("%d",&p);
for (int i=1;i<=p;i++){
int x;scanf("%d",&x);no[x]=1;
}
dij1();
dij2();
return 0;
}