#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int e[N], ne[N], h[N], ans[N], arr[N], in[N], idx;
int n;
void add(int a, int b)
{
e[idx] = b;
ne[idx] = h[a];
h[a] = idx++;
}
void topology()
{
queue<int> q;
for (int i = 1; i <= n; i++)
{
if (in[i] == 0)
{
q.push(i);
ans[i] = arr[i];
}
}
while (q.size())
{
int now = q.front();
q.pop();
for (int i = h[now]; i != -1; i = ne[i]) // · 遍历每条边;
{
int j = e[i];
ans[j] = max(ans[j], ans[now] + arr[j]);
in[j]--;
if (in[j] == 0)
{
q.push(j);