比赛 |
2025暑期集训第5场图论专场 |
评测结果 |
AAAAAAAAAA |
题目名称 |
Timeline |
最终得分 |
100 |
用户昵称 |
李奇文 |
运行时间 |
0.366 s |
代码语言 |
C++ |
内存使用 |
4.87 MiB |
提交时间 |
2025-07-09 09:29:56 |
显示代码纯文本
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+5;
int n,m,c;
int s[N];
int hd[N*2],tot;
struct node{
int v,nxt,w;
}e[N*2];
void add(int x,int y,int z){
e[++tot].v=y;
e[tot].w=z;
e[tot].nxt=hd[x];
hd[x]=tot;
}
queue<int> q;
int t[N];
signed main(){
freopen("usaco_Feb_timeline.in","r",stdin);
freopen("usaco_Feb_timeline.out","w",stdout);
scanf("%d%d%d",&n,&m,&c);
for(int i=1;i<=n;i++){
scanf("%d",&s[i]);
}
for(int i=1;i<=c;i++){
int a,b,x;
scanf("%d%d%d",&a,&b,&x);
add(a,b,x);
t[b]++;
}
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=hd[u];i;i=e[i].nxt){
int v=e[i].v,w=e[i].w;
s[v]=max(s[v],s[u]+w);
t[v]--;
if(!t[v]) q.push(v);
}
}
for(int i=1;i<=n;i++){
printf("%d\n",s[i]);
}
return 0;
}