QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#706201#6705. Medianfutarian#AC ✓2ms3860kbC++142.3kb2024-11-03 09:17:582024-11-03 09:17:59

Judging History

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

  • [2024-11-03 09:17:59]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3860kb
  • [2024-11-03 09:17:58]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
const int Len = 105;
int n,m,head[Len],cnt,in[Len],bg[Len],sm[Len];
bitset<105> bst[Len];
struct E
{
	int x,y;
	E(){x = y = 0;}
	E(int X,int Y){x = X , y = Y;}
}ee[Len * Len];
struct node
{
	int next,to;
}edge[Len * Len * 2];
inline void add(int from,int to)
{
	edge[++ cnt].to = to;
	edge[cnt].next = head[from];
	head[from] = cnt;
}
inline void clr(){cnt = 0;for(int i = 1 ; i <= n ; i ++) bst[i].reset() , bst[i].set(i , 1);memset(head , 0 , sizeof head);memset(in , 0 , sizeof in);}
inline void Top()
{
	queue<int> Q;
	for(int i = 1 ; i <= n ; i ++) if(!in[i]) bst[i].set(i , 1) , Q.push(i);
	while(!Q.empty())
	{
		int p = Q.front();Q.pop();
		for(int e = head[p] ; e ; e = edge[e].next)
		{
			int to = edge[e].to;
			in[to] --;
			bst[to] |= bst[p];
			if(!in[to]) Q.push(to);
		}	
	}
}
inline void work()
{
	clr();
	for(int i = 1 ; i <= m ; i ++) add(ee[i].x , ee[i].y) , in[ee[i].y] ++;
	Top();
}
int fa[Len];
inline bool cir()
{
	clr();	
	for(int i = 1 ; i <= m ; i ++) add(ee[i].x , ee[i].y) , in[ee[i].y] ++;
	queue<int> Q;int nms = 0;
	for(int i = 1 ; i <= n ; i ++) if(!in[i]) Q.push(i) , nms ++;
	while(!Q.empty())
	{
		int p = Q.front();Q.pop();
		for(int e = head[p] ; e ; e = edge[e].next)
		{
			int to = edge[e].to;
			in[to] --;
			if(!in[to]) Q.push(to) , nms ++;
		}	
	}
	return nms == n;
}
signed main()
{
	int T;scanf("%d",&T);
	while(T --)
	{
		scanf("%d %d",&n,&m);
		for(int i = 1 ; i <= m ; i ++)
		{
			int x,y;scanf("%d %d",&x,&y);
			ee[i] = E(x , y);
		}
		if(!cir()) 
		{
			for(int i = 1 ; i <= n ; i ++) putchar('0');
			puts("");
			continue;
		}
		work();
		for(int i = 1 ; i <= n ; i ++) bg[i] = bst[i].count() - 1;
		for(int i = 1 ; i <= m ; i ++) swap(ee[i].x , ee[i].y);
		work();
		for(int i = 1 ; i <= n ; i ++) sm[i] = bst[i].count() - 1;
		for(int i = 1 ; i <= n ; i ++)
		{
			int res = 1 , mn , mx;
			mn = sm[i] + 1 , mx = sm[i] + (n - bg[i] - sm[i]) + 1;
			res &= mn <= ((n + 1) / 2) && ((n + 1) / 2) <= mx;
			swap(sm[i] , bg[i]);
			mn = sm[i] + 1 , mx = sm[i] + (n - bg[i] - sm[i]) + 1;
			res &= mn <= ((n + 1) / 2) && ((n + 1) / 2) <= mx;
			if(res) putchar('1');
			else putchar('0');
		}
		puts("");
	}
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 3836kb

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