Submission #171464

# Submission time Handle Problem Language Result Execution time Memory
171464 2019-12-28T17:21:41 Z VEGAnn Shymbulak (IZhO14_shymbulak) C++14
0 / 100
1500 ms 10596 KB
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define PB push_back
#define MP make_pair
#define ft first
#define sd second
#define pll pair<ll, ll>
#define pii pair<int, int>
using namespace std;
typedef long long ll;
const ll OO = 1e18;
const int oo = 2e9;
const int N = 200100;
const int M = 1010;
vector<int> g[N], vc, cyc;
set<pii> st;
bool in_cyc[N];
int n, ans = 0, dst[N], mx = 0, mrk[N], up[N], pos[N];

void CYCLE(int lst){
    cyc.clear();
    int it = sz(vc) - 1;
    while (1){
        cyc.PB(vc[it]);
        in_cyc[vc[it]] = 1;
        if (vc[it] == lst)
            break;
        it--;
    }
}

void dfs(int v, int p){
    if (sz(cyc) > 0) return;
    vc.PB(v);
    mrk[v] = 1;
    for (int u : g[v]){
        if (u == p) continue;
        if (mrk[u] == 0)
            dfs(u, v); else
        if (mrk[u] == 1)
            CYCLE(u);
    }
    mrk[v] = 2;
    vc.pop_back();
}

void DFS(int v, int p){
    for (int u : g[v]){
        if (u == p || mrk[u]) continue;
        up[u] = up[v];
        DFS(u, v);
    }
}

bool ok(int x, int y){
    if (sz(cyc) & 1) return 0;
    return ((pos[up[x]] - pos[up[y]] + sz(cyc)) % sz(cyc)) == (sz(cyc) >> 1);
}

int main(){
    cin >> n;
    for (int i = 0; i < n; i++){
        int x, y; cin >> x >> y;
        x--; y--;
        g[x].PB(y); g[y].PB(x);
    }
    dfs(0, -1);
    for (int it = 0; it < sz(cyc); it++) {
        int cr = cyc[it];
        pos[cr] = it;
        up[cr] = cr;
        DFS(cr, -1);
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++) {
            dst[j] = oo;
            mrk[j] = 0;
        }
        dst[i] = 0;
        st.insert(MP(0, i));
        while (sz(st)){
            int v = (*st.begin()).sd;
            mrk[v] |= in_cyc[v];
            st.erase(st.begin());
            for (int u : g[v])
                if (dst[u] > dst[v] + 1){
                    st.erase(MP(dst[u], u));
                    mrk[u] = mrk[v];
                    dst[u] = dst[v] + 1;
                    st.insert(MP(dst[u], u));
                }
        }
        for (int v = 0; v < n; v++) {
            if (dst[v] > mx) {
                mx = dst[v];
                ans = 0;
            }
            if (dst[v] == mx)
                ans += (ok(i, v) ? 2 : 1);
        }
    }
    cout << ans / 2;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 5100 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 5116 KB Output is correct
6 Incorrect 6 ms 4984 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 5112 KB Output is correct
2 Correct 125 ms 5112 KB Output is correct
3 Correct 97 ms 5240 KB Output is correct
4 Correct 184 ms 5112 KB Output is correct
5 Execution timed out 1567 ms 5408 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1568 ms 10596 KB Time limit exceeded
2 Halted 0 ms 0 KB -