QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#537888#6705. MedianXiaoretaWWA 3ms3716kbC++202.4kb2024-08-30 19:24:372024-08-30 19:24:37

Judging History

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

  • [2024-08-30 19:24:37]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3716kb
  • [2024-08-30 19:24:37]
  • 提交

answer

#include <bits/stdc++.h>

#define debug(...) 42;
#ifdef LOCAL
#include "debug.h"
#endif

using namespace std;
#define V vector
#define fi first
#define se second
#define mp make_pair
#define sz(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define F(i, l, r) for (int i = l; i < r; ++i)
#define R(i, l, r) for (int i = r-1; i >= l; --i)
typedef long long LL;
typedef double DB;
typedef pair<int, int> PII;
template<typename T> bool setmin(T &a, T b) { return (a > b ? a = b, 1 : 0); }
template<typename T> bool setmax(T &a, T b) { return (a < b ? a = b, 1 : 0); }
// mt19937_64 rng {chrono::steady_clock::now().time_since_epoch().count()};

/* -------------Main code------------- */
void solve() {
    int n, m; cin >> n >> m;
    V<V<int>> g(n + 1), g_t(n + 1);
    V<int> d(n + 1), d_t(n + 1);
    F(i, 0, m) {
        int u, v; cin >> u >> v;
        d[v]++;
        d_t[u]++;
        g[u].emplace_back(v);
        g_t[v].emplace_back(u);
    }

    auto has = [&]() {
        V<int> q;
        F(i, 1, n + 1) if (d[i] == 0) q.push_back(i);
        for (int i = 0; i < sz(q); i++) {
            int u = q[i];
            for (int v : g[u]) if (--d[v] == 0) q.push_back(v);
        }
        for (int i = 1; i <= n; i++) if (d[i]) return true;
        return false;
    };

    if (has()) {
        cout << string(n, '0') << '\n';
        return;
    }

    V<int> comp1(n + 1, -1), comp2(n + 1, -1);
    auto dfs1 = [&](auto self, int u) -> int {
        if (comp1[u] != -1) return comp1[u];
        int res = 0;
        for (int v : g[u]) {
            res += self(self, v) + 1;
        }
        return comp1[u] = res;
    };
    auto dfs2 = [&](auto self, int u) -> int {
        if (comp2[u] != -1) return comp2[u];
        int res = 0;
        for (int v : g_t[u]) {
            res += self(self, v) + 1;
        }
        return comp2[u] = res;
    };
    for (int u = 1; u <= n; u++) {
        comp1[u] = dfs1(dfs1, u);
    }
    for (int u = 1; u <= n; u++) {
        comp2[u] = dfs2(dfs2, u);
    }
    // debug(comp1, comp2);
    for (int i = 1; i <= n; i++) {
        if (comp1[i] <= n / 2 and comp2[i] <= n / 2) cout << 1;
        else cout << 0;
    }
    cout << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int tt; cin >> tt;
    while (tt--) solve();

    return 0;
}

詳細信息

Test #1:

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

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: 3716kb

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

result:

wrong answer 2nd lines differ - expected: '01001000111', found: '00000000111'