QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#389115#6705. MedianMayuriWA 2ms3952kbC++201.3kb2024-04-14 02:34:352024-04-14 02:34:35

Judging History

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

  • [2024-04-14 02:34:35]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3952kb
  • [2024-04-14 02:34:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define endl '\n'
const ll maxn = 100 + 5;
ll T;
ll n, m;
vector<ll>to[maxn];
vector<ll>to2[maxn];
ll sz[maxn];
ll sz2[maxn];
bool vis[maxn];
void dfs(ll u, ll s) {
	if (vis[u]) return;
	vis[u] = true;
	sz[s]++;
	sz2[u]++;
	for (auto v : to[u]) {
		dfs(v, s);
	}
}
ll in[maxn];
bool topu() {
	queue<ll>q;
	for (ll i = 1; i <= n; i++)if (!in[i])
		q.push(i);
	while (!q.empty()) {
		ll u = q.front();
		q.pop();
		for (auto v : to[u]){
			in[v]--;
			if (!in[v])
				q.push(v);
		}
	}
	for (ll i = 1; i <= n; i++)if (in[i])
		return false;
	return true;
}
int main()//H
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> T;
	while (T--) {
		for (ll i = 1; i <= n; i++)sz[i] = sz2[i] = in[i] =0,to[i].clear(), to2[i].clear();
		cin >> n >> m;
		bool flag = true;
		for (ll i = 1; i <= m; i++) {
			ll a, b; cin >> a >> b;
			if (a == b)flag = false;
			to[a].push_back(b);
			in[b]++;
		}
		vector<bool>ans(n + 1);
		if (topu()&&flag) {
			for (ll i = 1; i <= n; i++) {
				memset(vis, false, sizeof(vis));
				dfs(i, i);
			}
		}
		for (ll i = 1; i <= n; i++) {
			if (sz[i] - 1 <= n / 2 && sz2[i] - 1 <= n / 2 && flag)ans[i] = true;
			else ans[i] = false;
			cout << ans[i];
		}
		cout << endl;
	}
}

詳細信息

Test #1:

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

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

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
11111
1111...

result:

wrong answer 26th lines differ - expected: '00000', found: '11111'