洛谷1113 杂务
原题链接
拓扑裸题。(其实可以不用建图就可以搞,不过我太懒了直接上拓扑
#include<cstdio>
using namespace std;
const int N = 1e4 + 10;
const int M = 1e6 + 10;
int fi[N], di[M], ne[M], q[M], v[N], T[N], ru[N], l, n, ma;
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
inline void add(int x, int y)
{
di[++l] = y;
ne[l] = fi[x];
fi[x] = l;
}
inline int maxn(int x, int y){ return x > y ? x : y; }
void topsort()
{
int i, head = 0, tail = 0, x, y;
for (i = 1; i <= n; i++)
if (!ru[i])
q[++tail] = i;
while (head ^ tail)
{
x = q[++head];
T[x] += v[x];
ma = maxn(ma, T[x]);
for (i = fi[x]; i; i = ne[i])
{
y = di[i];
T[y] = maxn(T[y], T[x]);
if (!(--ru[y]))
q[++tail] = y;
}
}
}
int main()
{
int i, x, y;
n = re();
for (i = 1; i <= n; i++)
{
y = re();
v[y] = re();
for (x = re(); x; x = re())
{
add(x, y);
ru[y]++;
}
}
topsort();
printf("%d", ma);
return 0;
}
posted on 2018-11-02 18:58 Iowa_Battleship 阅读(108) 评论(0) 编辑 收藏 举报