CodeForces 707B Bakery
枚举。
枚举每一条边,如果发现边的一端$f[u]=1$,另一端$f[v]=0$,那么更新答案,取最小值就好了。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<iostream> using namespace std; typedef long long LL; const double pi=acos(-1.0),eps=1e-6; void File() { freopen("D:\\in.txt","r",stdin); freopen("D:\\out.txt","w",stdout); } template <class T> inline void read(T &x) { char c = getchar(); x = 0;while(!isdigit(c)) c = getchar(); while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } } const int INF=0x7FFFFFFF; const int maxn=100010; int n,m,k; bool f[maxn]; struct X{int u,v,w;}s[maxn]; int main() { scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=m;i++) scanf("%d%d%d",&s[i].u,&s[i].v,&s[i].w); for(int i=1;i<=k;i++) { int x; scanf("%d",&x); f[x]=1; } int ans=INF; for(int i=1;i<=m;i++) { if(f[s[i].u]&&f[s[i].v]) continue; if(!f[s[i].u]&&!f[s[i].v]) continue; ans=min(ans,s[i].w); } if(ans==INF) printf("-1\n"); else printf("%d\n",ans); return 0; }