比赛 2025暑期集训第5场图论专场 评测结果 AAAAAAAAAA
题目名称 Timeline 最终得分 100
用户昵称 OTTF 运行时间 0.365 s
代码语言 C++ 内存使用 8.47 MiB
提交时间 2025-07-09 08:30:45
显示代码纯文本

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

template <typename T>
void read (T& num) {
    T res = 0;
	T ch = getchar();
	T op = 1;

    while (!isdigit (ch) && ch != EOF) {
		op = (ch == '-' ? -1 : 1);
        ch = getchar ();
	}

    while (isdigit (ch)) {
        res = (res * 10) + (ch - '0');
        ch = getchar ();
    }
    num = op * res;
}

class Read {
	public:
	Read operator>> (auto& other) {
		read (other);
		return (*this);
	}
};

Read in;

constexpr int N = 114514;

int n;
int m;
long long c;
vector<pair<int, long long>> graph[N];
int cc[N];
queue<int> q;
long long res[N];

int main () {
	
	freopen ("usaco_Feb_timeline.in", "r", stdin);
	freopen ("usaco_Feb_timeline.out", "w" ,stdout);

	in >> n >> m >> c;
	int w;
	graph[n + 1].emplace_back(0, 0);
	for (int i = 1; i <= n; i++) {
		in >> w;
		graph[0].emplace_back(i, w);
		cc[i]++;
	}

	int u, v;
	for (int i = 1; i <= c; i++) {
		in >> u >> v >> w;
		graph[u].emplace_back(v, w);
		cc[v]++;
	}

	q.push(0);
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		for (auto [v, w] : graph[u]) {
			res[v] = max (res[v], res[u] + w);
			cc[v]--;
			if (!cc[v]) {
				q.push(v);
			}
		}
	}

	for (int i = 1; i <= n; i++) {
		printf ("%lld\n", res[i]);
	}
	
	return 0;
}