人肉扒出了data1,原来自测和评测姬的结果真的能不一样。。。
查看原帖
人肉扒出了data1,原来自测和评测姬的结果真的能不一样。。。
50690
蒻得不行楼主2020/11/2 22:22

人肉程序:

#include<bits/stdc++.h>
using namespace std;
int a[100],i;
int main(){
	while(~scanf("%d",&a[i++]));
	printf("%d",a[13]);
	return 0;
}

扒出来的data1是这样的:

5 6
1 2
2 3
3 5
5 1
2 4
4 5

我的程序:

#include<bits/stdc++.h>
using namespace std;
int hd[10001],to[100001],nxt[100001],n,m,dfn[10001],low[10001],tail,_,__,ans,cnt[10001];
bool in[10001];
stack<int> s;
map<int,int> p;
void dfs(int x){
	low[x]=dfn[x]=++tail;
	in[x]=1;
	s.push(x);
	for(int i=hd[x];i;i=nxt[i]){
		if(!dfn[to[i]]) dfs(to[i]);
		if(in[to[i]]) low[x]=min(low[x],low[to[i]]);
	}
	if(low[x]==dfn[x]){
		while(s.top()^x){
			in[s.top()]=0;
			cnt[low[x]]++;
			s.pop();
		}
		cnt[low[x]]++;
		in[s.top()]=0;
		s.pop();
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&_,&__);
		nxt[i]=hd[_];
		to[i]=__;
		hd[_]=i;
	}
	for(int i=1;i<=n;i++) if(!dfn[i]) dfs(i);
	for(int i=1;i<=n;i++){
		p[low[i]]=p[low[i]];
		for(int j=hd[i];j;j=nxt[j]) if(low[i]^low[to[j]]) p[low[i]]++;
	}
	for(map<int,int>::iterator i=p.begin();i!=p.end();i++){
		if(!(*i).second){
			if(ans){
				puts("0");
				return 0;
			}
			ans=cnt[(*i).first];
		}
	}
	printf("%d",ans);
	return 0;
}

评测姬显示输出0,本机上输出5

2020/11/2 22:22
加载中...