大声求助P7551
  • 板块灌水区
  • 楼主mxxby
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/8/11 13:45
  • 上次更新2023/11/3 04:30:23
查看原帖
大声求助P7551
758793
mxxby楼主2023/8/11 13:45
#include<bits/stdc++.h>
#define lon long long
using namespace std;
lon n,m,q,zs,a,b,t,jg;
string x,y,s[1010];
lon bh[1010];
vector<pair<lon,lon> > sj[1010];
bool cx1,cx2;
int tc[1010];
void dfs(int x,int y,int h){
	if(tc[x]!=-1 && tc[x]<=h) return ;
	tc[x]= (tc[x]==-1) ? h : min(tc[x],h);
	if(x==y) return ;
	for(int i=0;i<sj[x].size();i++){
		dfs(sj[x][i].first,y,h+sj[x][i].second);
	}
	return ;
}
int main(){//字符串用map很合适,但我却不会qwq.. 
	std::ios::sync_with_stdio(false);
	cin.tie(0); 
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>x>>y>>t;
		cx1=cx2=0;
		for(int j=1;j<=zs;j++){
			if(s[j]==x){
				cx1=1;
				a=j;
			}
			if(s[j]==y){
				cx2=1;
				b=j;
			}
		}
		if(!cx1){
			s[++zs]=x;
			a=zs;
		}
		if(!cx2){
			s[++zs]=y;
			b=zs;
		}
		sj[a].push_back({b,t});
	}
	cin>>q;
	for(int i=1;i<=q;i++){
		for(int j=1;j<=n;j++) tc[j]=-1;
		cin>>x>>y;
		a=b=-1;
		for(int j=1;j<=n;j++){
			if(s[j]==x) a=j;
			if(s[j]==y) b=j;
		}
		if(a==-1 || b==-1) cout<<"Roger\n";
		else{
			dfs(a,b,0);
			if(tc[b]!=-1) cout<<tc[b]<<"\n";
			else cout<<"Roger\n";
		}
	}
	return 0;
}

WA两个点求助

2023/8/11 13:45
加载中...