QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#567930#9310. Permutation Counting 4EdGrassWA 0ms3532kbC++23959b2024-09-16 14:42:422024-09-16 14:42:43

Judging History

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

  • [2024-09-18 14:56:40]
  • hack成功,自动添加数据
  • (/hack/835)
  • [2024-09-18 14:41:06]
  • hack成功,自动添加数据
  • (/hack/831)
  • [2024-09-17 12:14:52]
  • hack成功,自动添加数据
  • (/hack/825)
  • [2024-09-16 14:42:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3532kb
  • [2024-09-16 14:42:42]
  • 提交

answer

#include<bits/stdc++.h>

using i64=long long;

void solve(){
	
	std::set<int>st;
	std::set<std::pair<int,int>>e;
	
	int n; std::cin>>n;

	std::vector<std::vector<int>>g(n+2);
	std::vector<std::array<int,2>>a(n);
	for(auto &[l,r]:a){
		std::cin>>l>>r;
	}

	for(int i=0;i<n;i++){
		auto [l,r]=a[i];
		g[l].push_back(r+1);
		if(e.count({l,r+1})){
			std::cout<<"0\n";
			return ;
		}
		e.insert({l,r+1});
		st.insert(l);
		st.insert(r+1);
	}

	if(!st.count(1)||st.size()!=e.size()+1){
		std::cout<<"0\n";
		return;
	}

	std::vector<int>fl(n+2,0);
	auto dfs=[&](auto self,int u) -> void {
		fl[u]=1;
		for(auto v:g[u]){
			if(fl[v])continue;
			self(self,v);
		}
	};
	dfs(dfs,1);

	for(auto v:st){
		if(!fl[v]){
			std::cout<<0<<'\n';
			return;
		}
	}

	std::cout<<1<<'\n';
	return;

}

signed main(){

	std::cin.tie(0) -> sync_with_stdio(false);

	int t=1; std::cin>>t;

	while(t--)
		solve();

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3532kb

input:

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

output:

0
0
0
0

result:

wrong answer 2nd words differ - expected: '1', found: '0'