比赛 |
2025暑期集训第5场图论专场 |
评测结果 |
AAAAAAAAAA |
题目名称 |
Timeline |
最终得分 |
100 |
用户昵称 |
rb_tree |
运行时间 |
0.654 s |
代码语言 |
C++ |
内存使用 |
5.70 MiB |
提交时间 |
2025-07-09 08:29:24 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int x=0,w=1;
char ch=0;
while(ch<'0'||ch>'9')
{
if(ch=='-') w=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*w;
}
inline void write(int x)
{
if(x<0)
{
x=-x;
putchar('-');
}
if(x>=10) write(x/10);
putchar((x%10)^48);
}
const int M=2e5+5,N=1e5+5;
int h[N],nxt[M],val[M],to[M],_cnt,n,m,c,dis[N],cnt[N],vis[N];
void add_edge(int a,int b,int c)
{
to[++_cnt]=b;
val[_cnt]=c;
nxt[_cnt]=h[a];
h[a]=_cnt;
}
void spfa(int s)
{
memset(dis,0x3f,sizeof(dis));
queue<int> q;
q.push(s);
dis[s]=0;
cnt[s]++;
vis[s]=1;
while(!q.empty())
{
int u=q.front();
q.pop();
vis[u]=0;
for(int i=h[u];i;i=nxt[i])
{
int v=to[i],w=val[i];
if(dis[v]>dis[u]+w)
{
dis[v]=dis[u]+w;
if(!vis[v])
{
q.push(v);
vis[v]=1;
cnt[v]++;
if(cnt[v]>=n) return;
}
}
}
}
}
int main()
{
freopen("usaco_Feb_timeline.in","r",stdin);
freopen("usaco_Feb_timeline.out","w",stdout);
n=read(),m=read(),c=read();
for(int i=1;i<=n;i++) add_edge(0,i,-read());
for(int i=1;i<=c;i++)
{
int a=read(),b=read(),x=read();
add_edge(a,b,-x);
}
spfa(0);
for(int i=1;i<=n;i++) write(-dis[i]),putchar('\n');
fclose(stdin);
fclose(stdout);
return 0;
}