莫名WA
查看原帖
莫名WA
73992
resftlmuttmotw楼主2020/11/4 12:59

题目

下下来数据本地是过了的 但提交后是WA。。。

下下来的数据:

input
10 20
970 369 910 889 470 106 658 659 916 964 
3 2
3 6
3 4
9 5
8 3
5 8
9 1
9 7
9 8
7 5
3 7
7 8
1 7
10 2
1 10
4 8
2 6
3 1
3 5
8 5

6911

code:code:

#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
using namespace std;
#define reg register int
#define isdigit(x) (x <= '9'&&x >= '0')
template <typename T>
inline T Read(T Type)
{
	T x = 0,f = 1;
	char a = getchar();
	while(!isdigit(a)) {if(a == '-') f = -1;a = getchar();}
	while(isdigit(a)) {x = (x << 1) + (x << 3) + (a ^ '0');a = getchar();}
	return x * f;
}
const int MAXN = 1e4 + 5,MAXM = 1e5 + 5;
stack<int> ascc;
bool isstack[MAXN];
vector<int> bh[MAXN],ah[MAXN],seq;
int n,m,cnt,tot_dfn,tot_scc,ans,fir[MAXN],dp[MAXN];
struct EDGE{int u,v,nxt;} edge[MAXM];
struct POINT{int pow,dfn,low,wscc;} p[MAXN];
struct SCC{int In,pow;} scc[MAXN];
inline void addedge(int u,int v) { edge[++cnt].v = v,edge[cnt].u = u,edge[cnt].nxt = fir[u],fir[u] = cnt;}
inline void tarjan(int x)
{
	p[x].low = p[x].dfn = ++tot_dfn,ascc.push(x),isstack[x] = 1;
	for(reg e = fir[x];e;e = edge[e].nxt)
	{
		int v = edge[e].v;
		if(!p[v].dfn) tarjan(v),p[x].low = min(p[x].low,p[v].low);
		else if(isstack[v]) p[x].low = min(p[x].low,p[v].dfn);
	}
	if(p[x].low == p[x].dfn)
	{
		scc[++tot_scc].In = scc[tot_scc].pow = 0;
		while(1)
		{
			int it = ascc.top();ascc.pop(),isstack[it] = 0;
			scc[tot_scc].pow += p[it].pow,p[it].wscc = tot_scc;
			if(it == x) break;
		}
	}
}
inline void topo()
{
	queue<int> q;
	for(reg i = 1;i <= tot_scc;i++) if(!scc[i].In) q.push(i);
	while(!q.empty())
	{
		int it = q.front();q.pop();
		seq.push_back(it);
		for(reg i = 0;i < bh[it].size();i++)
		{
			int nxt = bh[it][i];scc[nxt].In--;
			if(!scc[nxt].In) q.push(nxt);
		}
	}
}
int main()
{
	n = Read(1),m = Read(1);
	for(reg i = 1;i <= n;i++) p[i].pow = Read(1);
	for(reg i = 1;i <= m;i++)
	{
		int u = Read(1),v = Read(1);
		addedge(u,v);
	}
	for(reg i = 1;i <= n;i++) if(!p[i].dfn) {tarjan(i);}
	for(reg i = 1;i <= m;i++)
	{
		int u = edge[i].u,v = edge[i].v;
		if(p[u].wscc != p[v].wscc) scc[p[v].wscc].In++,bh[p[u].wscc].push_back(p[v].wscc),ah[p[v].wscc].push_back(p[u].wscc);
	}
	topo();
	for(reg i = 0;i < seq.size();i++)
	{
		int x = seq[i];dp[x] = scc[x].pow;
		for(reg j = 0;j < ah[x].size();j++)
			dp[x] = max(dp[x],dp[ah[x][j]] + scc[x].pow);
		ans = max(ans,dp[x]);
	}
	printf("%d\n",ans);
	return 0;
}
2020/11/4 12:59
加载中...