QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#254051#6705. MedianLionel_ZQY#AC ✓10ms3720kbC++201.3kb2023-11-17 23:19:062023-11-17 23:19:08

Judging History

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

  • [2023-11-17 23:19:08]
  • 评测
  • 测评结果:AC
  • 用时:10ms
  • 内存:3720kb
  • [2023-11-17 23:19:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

void solve(){
	int n,m;
	cin>>n>>m;
	vector<int> edge1[n+1],edge2[n+1];
	bool ok=true;
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		if(u==v){
			ok=false;
			continue;
		}
		edge1[u].push_back(v);
		edge2[v].push_back(u);
	}

	vector<int> ans(n+1),ls(n+1),rs(n+1);
	vector<bool> vis(n+1);

	function<void(int,int)> dfs1=[&](int u,int v){
		if(vis[u]){
			if(u==v) ok=false;
			return ;
		}

		vis[u]=true;
		ls[v]++;
		for(auto x:edge1[u]){
			dfs1(x,v);
		}
	};
	function<void(int,int)> dfs2=[&](int u,int v){
		if(vis[u]){
			if(u==v) ok=false;
			return ;
		}

		vis[u]=true;
		rs[v]++;
		for(auto x:edge2[u]){
			dfs2(x,v);
		}
	};

	for(int i=1;i<=n;i++){	
		vis.assign(n+1,false);
		dfs1(i,i);
		// cout<<i<<' '<<ok<<'\n';
	}
	for(int i=1;i<=n;i++){
		vis.assign(n+1,false);
		dfs2(i,i);
		// cout<<"/ "<<i<<' '<<ok<<'\n';	
	}

	if(!ok){
		for(int i=1;i<=n;i++){
			cout<<0;
		}
		cout<<'\n';
	}else{
		int k=(n+1)/2;
		for(int i=1;i<=n;i++){
			// cout<<i<<' '<<ls[i]<<' '<<rs[i]<<'\n';
			if(ls[i]<=k&&rs[i]<=n-k+1) cout<<1;
			else cout<<0;
		}
		cout<<'\n';
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);

	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

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

output:

01000
000

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 10ms
memory: 3720kb

input:

66
13 2
9 13
7 11
11 19
9 1
8 1
5 1
2 8
4 2
2 1
5 2
6 3
3 11
3 2
4 6
6 10
9 8
3 5
1 7
5 8
3 9
4 9
6 7
3 1
2 3
11 6
9 4
1 6
5 2
1 5
4 6
8 4
15 15
10 6
15 8
7 6
11 1
5 2
3 4
11 13
4 6
10 12
10 13
1 6
15 2
5 12
13 14
5 3
15 86
14 12
8 1
14 9
8 15
5 10
1 9
11 2
6 2
7 10
10 13
14 5
4 13
5 8
4 10
13 9
6 9...

output:

1111111111111
01001000111
111
11111111111
111111111111111
001001000000000
00100
01100
1111111
1000000000000
111101101
111111111
000011111011101
010111111
001100000
0100001001101
1111111111111
001000010000000
10010111011
001000000000100
11111111111
00100000011
11111
01000000110
11101110111
00000
1111...

result:

ok 66 lines