QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#389089 | #6705. Median | Mayuri | WA | 0ms | 16752kb | C++14 | 4.1kb | 2024-04-14 02:06:45 | 2024-04-14 02:06:45 |
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];
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;
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 16752kb
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: 0ms
memory: 16424kb
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 00000000111 111 11111111111 111111111111111 000000000000000 00000 01000 1111111 0000000000000 111000101 111111111 000000001010000 010111111 000000000 0000000000000 1111111111111 000000000000000 00000101001 000000000000000 11111111111 00000000000 11111 00000000000 11101110111 00000 0000...
result:
wrong answer 2nd lines differ - expected: '01001000111', found: '00000000111'