HOGWARTS333 @ 2019-07-30 23:15:24
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=10005;
const ll INF=1e9+5;
ll n,m,b;
struct Node{
ll end; //相邻节点
ll val; //路径权值
Node(ll _end,ll _val):end(_end),val(_val){};
};
vector<Node> G[maxn];
ll f[maxn];
ll min_maxfee=INF;
bool vis[maxn];
void dfs(ll u,ll maxfee,ll sumval) //路径上的最大收费点maxfee,边权之和sumval
{
if(maxfee>min_maxfee) return;
if(sumval>=b) return;
if(u==n){
if(maxfee<min_maxfee) min_maxfee=maxfee;
return;
}
vis[u]=true;
int len=G[u].size();
for(int i=0;i<len;++i)
{
ll end=G[u][i].end;
ll val=G[u][i].val;
if(vis[end]==false)
{
vis[end]=true;
dfs(end,max(maxfee,f[end]),sumval+val);
vis[end]=false;
}
}
vis[u]=false;
}
int main()
{
cin>>n>>m>>b;
ll maxf=0;
for(int i=1;i<=n;++i)
{
cin>>f[i];
maxf=max(maxf,f[i]);
}
int x,y,z;
for(int i=1;i<=m;++i)
{
cin>>x>>y>>z;
G[x].push_back(Node(y,z));
G[y].push_back(Node(x,z));
}
dfs(1,f[1],0);
if(min_maxfee==INF) cout<<"AKF"<<endl;
else cout<<min_maxfee<<endl;
return 0;
}
by Hexarhy @ 2019-07-30 23:20:08
@HOGWARTS333 这题不是二分+最短路?
by Hexarhy @ 2019-07-30 23:20:30
@HOGWARTS333 debug就算了
by HOGWARTS333 @ 2019-07-30 23:25:02
@HyyypRtf06 我知道是二分+最短路,也写出来了,但只是突发奇想DFS能不能写
by yu55555 @ 2019-08-24 15:26:59
dfs不超时吗