QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#119936#873. Königsberg BridgesteruelWA 359ms309296kbC++143.5kb2023-07-06 07:23:082023-07-06 07:23:08

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:23:08]
  • Judged
  • Verdict: WA
  • Time: 359ms
  • Memory: 309296kb
  • [2023-07-06 07:23:08]
  • 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[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++;
        tin[i] = low[i] = -1;
    }

    int col = 0;
    for(int i = 1; i <= c; i++) {
        int rt = G[i][0];
        dfs2(rt);
        for(int x : G[i])
            if(!Id[x])
                dfs3(x, ++col);
        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';
}

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: 100
Accepted
time: 35ms
memory: 261528kb

input:

4 3
0 1
1 2
2 0

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 36ms
memory: 263524kb

input:

4 2
0 1
1 2

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: -100
Wrong Answer
time: 359ms
memory: 309296kb

input:

266912 867557
0 31522
0 174162
0 4209
1 58647
1 5722
1 24762
1 258525
1 148028
1 72989
1 170812
1 260494
1 86533
1 212481
2 143457
2 47080
2 72841
2 113512
2 64754
2 231454
3 220536
3 97144
3 183508
3 177546
3 149060
3 140197
3 87427
3 169096
4 132318
4 67337
4 23014
4 34254
4 11851
4 12558
4 49756
...

output:

378

result:

wrong answer 1st numbers differ - expected: '380', found: '378'