标签:pop 就是 tchar 啊啊啊 front algorithm || queue 思想
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define ll long long
using namespace std;
inline int read(){
int x=0,o=1;char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')o=-1,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*o;
}
const int N=250;
const int M=1005;
int val,m,n,k,s;
int visit[N],dis[N],in[N];
int tot,head[N],nxt[M],to[M],w[M];
inline void add(int a,int b,int c){
nxt[++tot]=head[a];head[a]=tot;
to[tot]=b;w[tot]=c;
}
queue<int>q;
inline void spfa(){
q.push(s);dis[s]=val;in[s]=1;++visit[s];
//in[]是否在队列中,visit[]出队次数
while(q.size()){
int u=q.front();q.pop();in[u]=0;
if(++visit[u]>n){printf("-1\n");return;}
for(int i=head[u];i;i=nxt[i]){
int v=to[i];
if(dis[v]<dis[u]+w[i]){
dis[v]=dis[u]+w[i];
if(!in[v]){
q.push(v);
in[v]=1;
}
}
}
}
int ans=0;
for(int i=1;i<=n;++i)ans=max(ans,dis[i]);
printf("%d\n",ans);
}
int main(){
val=read();m=read();n=read();k=read();s=read();
for(int i=1;i<=m;++i){
int a=read(),b=read();
add(a,b,val);
}
for(int i=1;i<=k;++i){
int a=read(),b=read(),c=read();
add(a,b,val-c);
}
spfa();
return 0;
}
标签:pop 就是 tchar 啊啊啊 front algorithm || queue 思想
原文地址:https://www.cnblogs.com/PPXppx/p/11562034.html