QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858284#9677. 基础博弈练习题Tx_Lcy0 80ms124952kbC++141.7kb2025-01-16 15:37:462025-01-16 15:37:51

Judging History

你现在查看的是最新测评结果

  • [2025-01-16 15:37:51]
  • 评测
  • 测评结果:0
  • 用时:80ms
  • 内存:124952kb
  • [2025-01-16 15:37:46]
  • 提交

answer

//A tree without skin will surely die.
//A man without face will be alive.
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
int const N=1e6+10;
int n,m,k,a[N],b[N],f[N],co[N],rd[N],dfn[N],low[N],cnt,s[N],top;
vector<int>e[N],E[N],V[N],vec[N];bool vis[N];
inline void tarjan(int x){
	dfn[x]=low[x]=++cnt,vis[x]=1,s[++top]=x;
	for (auto v:e[x])
		if (!dfn[v]) tarjan(v),low[x]=min(low[x],low[v]);
		else if (vis[v]) low[x]=min(low[x],dfn[v]);
	if (dfn[x]==low[x]){
		++co[0];
		while (1){
			int X=s[top--];
			co[X]=co[0],vis[X]=0,V[co[0]].push_back(X);
			if (X==x) break;
		}
	}
}
inline void solve(){
	cin>>n>>m>>k;
	rep(i,1,n) cin>>a[i];
	rep(i,1,k) cin>>b[i],vec[b[i]].push_back(i);
	memset(f,0x3f,sizeof(f));
	rep(i,1,m){
		int u,v;cin>>u>>v;
		e[u].push_back(v);
	}
	rep(i,1,n) if (!dfn[i]) tarjan(i);
	rep(i,1,n) for (auto j:e[i])
		if (co[i]^co[j]) E[co[j]].push_back(co[i]),++rd[co[i]];
	queue<int>q;
	rep(i,1,co[0]) if (!rd[i]) q.push(i);
	while (!q.empty()){
		int x=q.front();q.pop();
		if (V[x].size()>1){
			vector<int>v;
			for (auto y:V[x]) for (auto it:vec[a[y]]) v.push_back(it);
			sort(all(v),greater<>());
			for (auto val:v) if (val<=k && val+1<f[x]) f[x]=min(f[x],val);
		}
		for (auto v:E[x]){
			f[v]=min(f[v],f[x]);
			if (V[x].size()==1){
				int val=vec[a[V[x][0]]][0];
				if (val<=k && val+1<f[x]) f[v]=min(f[v],val);
			}
			if (!--rd[v]) q.push(v);
		}
	}
	rep(i,1,n)
		if (f[co[i]]>k) cout<<"-1 ";
		else cout<<f[co[i]]-1<<' ';
	cout<<'\n';
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int t=1;
	// cin>>t;
	while (t--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

83 93 13
8 9 10 7 7 7 6 3 1 10 6 2 5 7 1 3 4 2 1 10 7 4 8 9 2 2 1 9 2 5 1 7 8 6 1 9 9 10 4 1 2 9 2 3 4 2 9 10 8 1 4 1 8 4 1 4 4 7 4 8 2 9 2 5 2 2 3 3 8 5 2 9 3 10 8 8 1 6 6 1 6 7 10
7 5 10 3 2 2 7 4 8 7 6 6 5
56 36
33 41
32 62
37 7
6 53
41 13
9 36
44 77
38 62
76 16
72 5
40 13
55 60
5 78
72 45
13 44
...

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Runtime Error

Test #6:

score: 30
Accepted
time: 80ms
memory: 124952kb

input:

100000 355071 10000
5 7 4 7 4 1 10 5 9 4 9 4 3 10 5 4 9 1 7 10 1 6 10 3 10 9 8 4 6 3 10 8 6 8 3 5 10 9 7 7 1 3 8 8 6 2 8 4 2 9 1 10 3 6 3 8 9 10 5 7 3 2 1 5 7 4 3 4 6 4 2 7 2 5 5 6 4 6 7 4 4 6 4 2 3 9 9 9 10 8 1 6 7 2 9 8 2 3 1 6 9 4 10 3 10 1 2 3 3 4 1 1 1 5 8 6 8 3 1 6 2 9 5 9 4 7 2 10 7 5 2 2 7 4...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 100000 numbers

Test #7:

score: 30
Accepted
time: 69ms
memory: 121608kb

input:

100000 300561 10000
6 3 6 10 10 9 7 3 6 4 5 4 1 2 3 2 10 6 3 7 8 7 10 5 9 10 2 3 9 5 6 10 9 1 4 9 1 10 7 2 9 10 5 5 9 3 5 5 5 9 9 5 1 7 5 10 8 6 8 4 5 9 2 10 1 6 4 10 10 9 2 1 10 1 9 5 3 2 9 3 4 8 10 7 5 2 4 5 3 6 9 7 5 10 2 7 4 7 10 8 1 7 7 1 7 7 6 6 7 1 5 4 6 2 1 8 6 10 6 10 1 5 8 4 6 2 10 6 10 4 ...

output:

0 4 0 0 3 0 0 4 0 0 0 0 0 0 0 0 0 0 1 0 0 1 7 0 1 2 0 0 0 0 4 0 0 1 0 0 0 2 0 0 0 3 0 0 1 0 0 0 3 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 1 0 9 0 0 0 2 0 3 1 0 2 1 0 0 0 2 0 0 0 0 0 0 3 0 0 0 0 0 2 2 0 0 1 0 0 0 0 0 1 0 0 1 0 2 0 6 0 0 1 5 0 0 3 0 0 1 2 0 2 3 0 0 2 0 1 1 9 0 2 5 2 0 2 1 3 1 6 4 0 0 1 0 2 1 0 ...

result:

ok 100000 numbers

Test #8:

score: 0
Runtime Error

input:

500000 1770902 50000
4 7 2 3 6 10 8 2 2 6 2 3 3 7 3 1 5 2 1 10 2 6 3 4 2 8 10 6 6 10 9 3 3 2 9 10 4 5 3 9 7 10 4 3 6 6 4 9 4 4 4 1 9 5 6 10 3 7 5 8 10 1 6 5 1 7 9 10 2 4 6 9 6 2 2 8 4 7 9 1 9 4 6 4 6 3 9 2 2 1 1 1 8 3 10 10 2 2 5 15 20 18 17 15 12 11 11 11 11 12 13 19 18 20 15 11 11 20 10 14 13 14 1...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%