DFS为什么会有三个wa?!
  • 板块P1807 最长路
  • 楼主fuxueziyi
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/12/1 21:26
  • 上次更新2024/12/2 13:45:24
查看原帖
DFS为什么会有三个wa?!
1121276
fuxueziyi楼主2024/12/1 21:26

详情键代码:

#include<bits/stdc++.h>
using namespace std;
vector<int>ve[1501];
int rd[50001]={0},maxx=INT_MIN,flag=0;
void dfs(int x,int t,int mb){
	//cout<<x<<" "<<t<<" "<<mb<<endl;
	t+=rd[x];
	if(x==mb){
		maxx=max(t,maxx);
		flag=1;
		return;
	}
	for(auto to:ve[x]){
		dfs(to,t,mb);
	}
	return;
}
int main(){
	int m,u,v,t,n;
	cin>>n>>m;
	if(m==0){cout<<-1<<endl;return 0;}
	for(int i=1;i<=m;i++){
		cin>>u>>v>>t;
		ve[u].push_back(v);
		rd[i]=t;
	}
	dfs(1,0,n);
	if(flag==1) cout<<maxx<<endl;
	else cout<<-1<<endl;
}
2024/12/1 21:26
加载中...