QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#119940#873. Königsberg BridgesteruelWA 30ms259492kbC++143.6kb2023-07-06 07:29:222023-07-06 07:29:26

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 07:29:26]
  • Judged
  • Verdict: WA
  • Time: 30ms
  • Memory: 259492kb
  • [2023-07-06 07:29:22]
  • Submitted

answer

#include <bits/stdc++.h>

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline","03")
#endif // ONLINE_JUDGE

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define rnk(x, y) (upper_bound(all((x)), (y)) - (x).begin())

typedef long double ld;
typedef long long ll;
typedef __int128 LL;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

static int rnd(int lo, int hi) {
    return uniform_int_distribution <int> (lo, hi)(rng);
}

typedef pair <int, int> ii;

const ll oo = 1e12;

const ll MAX = 2e6 + 5;
const ll mod = 1e9 + 7;

int n, m, mark[MAX], it[MAX];

vector <int> ady[MAX], G[MAX], G2[MAX];

void dfs(int x, int c) {
    if(it[x])
        return;
    it[x] = c;
    G[c].push_back(x);
    for(int to : ady[x])
        dfs(to, c);
}

unordered_set <int> s[MAX];
int tin[MAX], low[MAX], timer, vis[MAX];

void Add(int x, int y) {
    if(x > y)swap(x, y);
    s[x].insert(y);
}

void dfs2(int v, int p = -1) {
    vis[v] = true;
    tin[v] = low[v] = timer++;
    for(int to : ady[v]) {
        if(to == p)
            continue;
        if(vis[to]) {
            low[v] = min(low[v], tin[to]);
        } else {
            dfs2(to, v);
            low[v] = min(low[v], low[to]);
            if(low[to] > tin[v])
                Add(v, to);
        }
    }
}

int Id[MAX];

bool Bridge(int x, int y) {
    if(x > y)swap(x, y);
    return s[x].count(y);
}

void dfs3(int x, int c) {
    Id[x] = c;
    for(int to : ady[x])
        if(!Bridge(x, to) && !Id[to])
            dfs3(to, c);
}

int D[MAX];

void dfs4(int x, int p = -1) {
    for(int to : G2[x])
        if(to != p && !D[to]) {
            D[to] = D[x] + 1;
            dfs4(to, x);
        }
}

void solve() {
    cin >> n >> m;

    while(m--) {
        int x, y;
        cin >> x >> y;
        x++, y++;
        ady[x].push_back(y);
        ady[y].push_back(x);
    }

    int c = 0, r = -1;

    for(int i = 1; i <= n; i++) {
        if(!it[i]) {
            dfs(i, ++c), r++;
            dfs2(i);
        }
        tin[i] = low[i] = -1;
    }

    for(int i = 1; i <= c; i++) {
        int rt = G[i][0], col = 0;
        for(int x : G[i])
            if(!Id[x])
                dfs3(x, ++col);
        if(n == 717331)
            cout << i << ' ' << col << '\n';
        for(int x : G[i])
            for(int to : ady[x])
                if(Id[to] != Id[x]) {
                    G2[Id[x]].push_back(Id[to]);
                    G2[Id[to]].push_back(Id[x]);
                }
        dfs4(1);
        rt = 1;
        for(int j = 2; j <= col; j++)
            if(D[j] > D[rt])
                rt = j;
        for(int j = 1; j <= col; j++)
            D[j] = 0;
        dfs4(rt);
        int top = 0;
        for(int j = 1; j <= col; j++) {
            top = max(top, D[j]);
            D[j] = 0;
        }
        r += top;
        G[i].clear();
        for(int j = 1; j <= col; j++)
            G2[i].clear();
    }

    cout << r << '\n';
    cout << ' ' << c << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

//    freopen("hack.in", "r", stdin);
//    freopen("hack.out", "w", stdout);

    int t = 1;
//    cin >> t;

    while(t--)
        solve();

    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 30ms
memory: 259492kb

input:

4 3
0 1
1 2
2 0

output:

1
 2

result:

wrong answer Output contains longer sequence [length = 2], but answer contains 1 elements