QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#537940#6705. MedianXiaoretaWAC ✓3ms3848kbC++202.8kb2024-08-30 19:55:272024-08-30 19:55:27

Judging History

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

  • [2024-08-30 19:55:27]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3848kb
  • [2024-08-30 19:55:27]
  • 提交

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------------- */
const int N = 110;
void solve() {
    bitset<N> f[N];
    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);
        f[u][v] = 1;
    }

    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;
    }

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (f[j][i])
                f[j] |= f[i];

    V<int> comp1(n + 1), comp2(n + 1);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (f[i][j])
                comp1[i]++, comp2[j]++;
    // 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;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

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: 0
Accepted
time: 3ms
memory: 3848kb

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

result:

ok 66 lines