QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#150777#4934. Forbidden CardKAxddRE 0ms0kbC++141.2kb2023-08-26 09:48:142023-08-26 09:48:16

Judging History

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

  • [2023-08-26 09:48:16]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-08-26 09:48:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int a[100005],b[100005],ans[100005];
int n,m,live[1000005],to[1000005],cnt,tot,v[1000005],num,talk[1000005];
vector<int> vis[1000005];
void dfs(int x) {
	tot++;cnt=0; 
	int flag=0;
	if(x==n+1) x=1; 
	int len=vis[a[x]].size();
	for(int i=0;i<len;i++) {
		int u=vis[a[x]][i];
		if(!live[u]) {
			to[u]=tot,v[++cnt]=u;
			if(!u) {
				flag++;
			}
		}
	}
	if(!flag) vis[a[x]].push_back(0),talk[a[x]]++; 
	len=vis[b[x]].size();
	for(int i=0;i<len;i++) {
		int u=vis[b[x]][i];
		if(!live[u] && to[u]==tot) {
			if(u==0) {
				ans[x]+=m-num;
				return ;
			}
			num++; ans[x]++; live[u]=true; 
		}
	}
	for(int i=1;i<=cnt;i++) {
		if(!live[v[i]]) {
			vis[b[x]].push_back(v[i]);
			if(!v[i]) talk[b[x]]++; 
		}
	}
	if(!flag && !live[a[x]] && talk[b[x]]) num++,ans[x]++,live[a[x]]=true;
	if(flag && !live[b[x]] && talk[a[x]]) num++,ans[x]++,live[b[x]]=true;
	dfs(x+1);
}
int main() {
	freopen("marketplace.in","r",stdin);
	freopen("marketplace.out","w",stdout);
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d %d",&a[i],&b[i]);
	for(int i=1;i<=m;i++) vis[i].push_back(i);
	dfs(1);
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

3 6
1 2
2 4
4 2

output:


result: