QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#719403#6705. MedianxunxxxxWA 8ms3940kbC++231.1kb2024-11-07 00:40:462024-11-07 00:40:47

Judging History

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

  • [2024-11-07 00:40:47]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3940kb
  • [2024-11-07 00:40:46]
  • 提交

answer

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

vector<int>g[110];
int pre[110];
int suf[110];
int f;
int n,m;
void bfs(int u)
{
	queue<int>q;
	q.push(u);
	vector<int>vt(n+1,0);
	
	while(!q.empty())
	{
		int u1=q.front();
		q.pop();
		if(vt[u1]) continue;
		vt[u1]=1;
		for(auto v:g[u1]) 
		{
			if(vt[v]) f=1;
			q.push(v);
		}
	}
	
	
	for(int i=1;i<=n;i++) if(i!=u&&vt[i]) pre[u]++,suf[i]++;
}
void solve()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) pre[i]=suf[i]=0,g[i].clear();
	f=0;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		if(u==v) f=1;
		g[u].push_back(v);
	}
	
	
//	for(int i=1;i<=n;i++) cout<<pre[i]<<" "<<suf[i]<<"\n";
	
	
//	f=0;
	for(int i=1;i<=n;i++) bfs(i);
	
//	for(int i=1;i<=n;i++) cout<<pre[i]<<" "<<suf[i]<<"\n";
	
	
	if(f)
	{
		string ans;
		while(n--) ans+='0';
		cout<<ans<<"\n";
	}
	else
	{
		string ans;
		for(int i=1;i<=n;i++) 
		if(pre[i]<=n/2&&suf[i]<=n/2) ans+='1';
		else ans+='0';
		
		cout<<ans<<"\n";
	}
	
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int T=1;
	cin>>T;
	while(T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 8ms
memory: 3940kb

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
00000000000
111
11111111111
111111111111111
000000000000000
00000
00000
1111111
0000000000000
000000000
111111111
000000000000000
000000000
000000000
0000000000000
1111111111111
000000000000000
00000000000
000000000000000
11111111111
00000000000
11111
00000000000
00000000000
00000
1111...

result:

wrong answer 2nd lines differ - expected: '01001000111', found: '00000000000'