QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#389088#6705. MedianMayuriWA 0ms16948kbC++144.1kb2024-04-14 02:06:122024-04-14 02:06:12

Judging History

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

  • [2024-04-14 02:06:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:16948kb
  • [2024-04-14 02:06:12]
  • 提交

answer

//#define _CRT_SECURE_NO_WARNINGS
//#include<bits/stdc++.h>
//using namespace std;
//typedef long long ll;
//typedef long double ld;
//#define endl '\n'
//const ll maxn = 2e5 + 5;
//ll T;
//ll n, m, k;
//ll u[maxn], v[maxn];
//
//int main()//D
//{
//	ios::sync_with_stdio(0);
//	cin.tie(0);
//	cout.tie(0);
//	cin >> T;
//	while (T--) {
//		cin >> k;
//		string s; cin >> s;
//		cin >> n >> m;
//		for (ll i = 1; i <= m; i++) {
//			ll u, v; cin >> u >> v;
//		}
//		ll d = m - n + 2;
//		d--;
//		ll t = d % k;
//		if (s[t] == '1') cout << 2 << endl;
//		else cout << 1 << endl;
//	}
//}
//#define _CRT_SECURE_NO_WARNINGS
//#include<bits/stdc++.h>
//using namespace std;
//typedef long long ll;
//typedef long double ld;
//#define endl '\n'
//const ll maxn = 2e5 + 5;
//ll T;
//ll n, m, k;
//ll u[maxn], v[maxn];
//ll dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
//ll f(char ch) {
//	if (ch == 'U')return 0;
//	if (ch == 'R')return 1;
//	if (ch == 'D')return 2;
//	if (ch == 'L')return 3;
//}
//int main()//C
//{
//	ios::sync_with_stdio(0);
//	cin.tie(0);
//	cout.tie(0);
//	cin >> T;
//	while (T--) {
//		cin >> n >> k;
//		string s; cin >> s;
//		ll bx = 0, by = 0;
//		ll mx = 0, my = 0;
//		ll mmax = 0;
//		for (ll i = 0; i < s.size(); i++) {
//			ll t = f(s[i]);
//			bx += dx[t];
//			by += dy[t];
//			if (abs(bx) + abs(by) > abs(mx) + abs(my)) {
//				mx = bx;
//				my = by;
//			}
//		}
//		bx = bx * (k - 1);
//		by = by * (k - 1);
//		ll tx = 0, ty = 0;
//		for (ll i = 0; i < s.size(); i++) {
//			ll t = f(s[i]);
//			bx += dx[t];
//			by += dy[t];
//			if (abs(bx) + abs(by) > abs(tx) + abs(ty)) {
//				tx = bx;
//				ty = by;
//			}
//		}
//		cout << max(abs(tx) + abs(ty), abs(mx) + abs(my)) << endl;
//	}
//}
//#define _CRT_SECURE_NO_WARNINGS
//#include<bits/stdc++.h>
//using namespace std;
//typedef long long ll;
//typedef long double ld;
//#define endl '\n'
//const ll maxn = 2e5 + 5;
//ll T;
//ll n, m;
//struct node {
//	ll l, r;
//	bool operator<(node t)const {
//		if (l == t.l) return r < t.r;
//		return l < t.l;
//	}
//}N[maxn];
//int main()//H
//{
//	ios::sync_with_stdio(0);
//	cin.tie(0);
//	cout.tie(0);
//	cin >> T;
//	while (T--) {
//		cin >> n;
//		for (ll i = 1; i <= n; i++) cin >> N[i].l >> N[i].r;
//		sort(N + 1, N + 1 + n);
//		ll cur = -1;
//		ll p = 1;
//		ll ans = 0;
//		priority_queue<ll, vector<ll>, greater<ll>>q;
//		while (p <= n) {
//			if (q.empty()) cur = N[p].l;
//			while (p <= n && cur == N[p].l) {
//				q.push(N[p].r);
//				p++;
//			}
//			while (q.size() && q.top() < cur)q.pop();
//			if (q.size() && cur <= q.top())ans++, q.pop();
//			cur++;
//		}
//		while (q.size()) {
//			if (q.top() >= cur) {
//				ans++;
//				cur++;
//			}
//			q.pop();
//		}
//		cout << ans << endl;
//	}
//}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define endl '\n'
const ll maxn = 2e5 + 5;
ll T;
ll n, m;
vector<ll>to[maxn];
vector<ll>to2[maxn];
ll sz[maxn];
ll sz2[maxn];
void dfs(ll u) {
	sz[u] = 1;
	for (auto v : to[u]) {
		dfs(v);
		sz[u] += sz[v];
	}
}
void dfs2(ll u) {
	sz2[u] = 1;
	for (auto v : to2[u]) {
		dfs2(v);
		sz2[u] += sz2[v];
	}
}
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++)to[i].clear(), to2[i].clear();
		cin >> n >> m;
		for (ll i = 1; i <= m; i++) {
			ll a, b; cin >> a >> b;
			to[a].push_back(b);
			in[b]++;
			to2[b].push_back(a);
		}
		vector<bool>ans(n + 1);
		if (topu()) {
			for (ll i = 1; i <= n; i++) {
				dfs(i); dfs2(i);
				if (sz[i] - 1 <= n / 2 && sz2[i] - 1 <= n / 2)ans[i] = true;
				//cout << i << " " << sz[i] << " " << sz2[i] << endl;
			}
		}
		for (ll i = 1; i <= n; i++)cout << ans[i] << " ";
		cout << endl;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

0 1 0 0 0 
0 0 0 

result:

wrong answer 1st lines differ - expected: '01000', found: '0 1 0 0 0 '