General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
187453894 Practice:
DaiRuiChen007
1704E - 98 C++14 (GCC 6-32) Accepted 93 ms 736 KB 2022-12-31 17:14:47 2022-12-31 17:14:47
→ Source
// LUOGU_RID: 98393046
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN=1001,MOD=998244353;
vector <int> G[MAXN];
int a[MAXN],deg[MAXN];
inline void solve() {
	int n,m;
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;++i) scanf("%lld",&a[i]),deg[i]=0,G[i].clear();
	for(int i=1;i<=m;++i) {
		int u,v;
		scanf("%lld%lld",&u,&v);
		G[u].push_back(v);
		++deg[v];
	}
	queue <int> q;
	vector <int> ord;
	for(int i=1;i<=n;++i) if(!deg[i]) q.push(i);
	while(!q.empty()) {
		int p=q.front(); q.pop();
		ord.push_back(p);
		for(int v:G[p]) {
			--deg[v];
			if(!deg[v]) q.push(v);
		}
	}
	for(int t=1;t<=n;++t) {
		bool ok=true;
		for(int i=1;i<=n;++i) if(a[i]!=0) ok=false;
		if(ok) {
			printf("%lld\n",t-1);
			return ;
		}
		vector <int> flow;
		for(int u:ord) if(a[u]!=0) flow.push_back(u);
		for(int u:flow) {
			--a[u];
			for(int v:G[u]) ++a[v];	
		}
	}
	for(int u:ord) for(int v:G[u]) a[v]=(a[v]+a[u])%MOD;
	printf("%lld\n",(a[ord[n-1]]+n)%MOD);
}
signed main() {
	int T;
	scanf("%lld",&T);
	while(T--) solve();
	return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details