QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#389101 | #6705. Median | Mayuri | WA | 3ms | 13344kb | C++14 | 4.1kb | 2024-04-14 02:22:31 | 2024-04-14 02:22:32 |
Judging History
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];
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++)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]++;
}
vector<bool>ans(n + 1);
if (topu()) {
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)ans[i] = true;
cout << ans[i];
}
cout << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 13144kb
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: 3ms
memory: 13344kb
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 000 00000000010 000000000111111 000000000000000 00000 00000 0000000 0000000000000 000000000 000000000 000000000000000 000000000 000000000 0000000000000 0000000000000 000000000000000 00000000000 000000000000000 00000000000 00000000000 00000 00000000000 00000000000 00000 0000...
result:
wrong answer 3rd lines differ - expected: '111', found: '000'