#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define M 10000
using namespace std;
int tot=0, head[M], nex[M], to[M], dis[M];
int d[M], vis[M], cnt[M];
int w, p, n, f, s, ans=0;
priority_queue<int, vector<int>, greater<int> > q;
inline int read()
{
int re=0, f=1; char ch=getchar();
while(ch<'0' || ch>'9') {if(ch=='-') f=-1; ch=getchar();}
while(ch>='0' && ch<='9') {re=re*10+(ch-'0'); ch=getchar();}
return re*f;
}
void add_edge(int x,int y,int z)
{
to[++tot]=y;
dis[tot]=z;
nex[tot]=head[x];
head[x]=tot;
}
void Spfa()
{
vis[s]=1; d[s]=w; cnt[s]++;
q.push(s);
//从超级源点s开始做 SPFA
while(!q.empty())
{
int u=q.top(); q.pop();
vis[u]=0;
if(++cnt[u]>n+1) {printf("orz\n"); exit(0);}
for(int i=head[u];i;i=nex[i])
{
int v=to[i];
if(d[v]<d[u]+dis[i])
{
d[v]=d[u]+dis[i];
if(!vis[v])
{
vis[v]=1;
q.push(v);
}
}
}
}
}
int main()
{
w=read(); p=read(); n=read(); f=read(); s=n+1; //超级源点s
for(int i=1;i<=p;++i)
{
int x=read(), y=read();
add_edge(x,y,w);
}
for(int i=1;i<=f;++i)
{
int x=read(), y=read(), z=read();
add_edge(x,y,w-z);
}
for(int i=1;i<=n;++i) add_edge(s,i,0); //给超级源点s加边
Spfa();
for(int i=1;i<=n+1;++i) ans=max(ans,d[i]);
printf("%d\n",ans);
return 0;
}剪贴板
剪贴板 7g9jq0xe
剪贴板信息
剪贴板信息
- 收录
- 更新