求调
查看原帖
求调
370648
柠檬布丁吖楼主2023/3/11 18:01
#include<bits/stdc++.h>

using namespace std;
#define int long long
inline int read(){
	int ret=0,f=1;
	char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-f;
	for(;c>='0'&&c<='9';c=getchar()) ret=ret*10+c-'0';
	return ret*f;
}
const int maxn=1e6+55;
struct g{
	int v,w,next;
}e[maxn];
int s[maxn],t[maxn],head[maxn],cnt;
queue<int> q;

void addedge(int u,int v,int w){
	e[++cnt].v=v;
	e[cnt].w=w;
	e[cnt].next=head[u];
	head[u]=cnt;
}

signed main(void){
	
	int n,m,c;
	n=read();m=read();c=read();
	
	for(int i=1;i<=n;i++){
		s[i]=read();
	}
	
	for(int i=1;i<=c;i++){
		int u,v,w;
		u=read();v=read();w=read();
		addedge(u,v,w);
		t[v]++;
	}
	
	for(int i=1;i<=n;i++){
		if(!t[i]) q.push(i);
	}
	
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=head[u];i;i=e[i].next){
			int v=e[i].v,w=e[i].w;
			s[v]=max(s[v],s[u]+v);
			t[v]--;
			if(!t[v]) q.push(v);
		}
	}
	
	for(int i=1;i<=n;i++){
		cout<<s[i]<<endl;
	}
	
	return 0;
}
2023/3/11 18:01
加载中...