Submission #52337

# Submission time Handle Problem Language Result Execution time Memory
52337 2018-06-25T12:55:21 Z Alexa2001 007 (CEOI14_007) C++17
66.6667 / 100
319 ms 27960 KB
#include <bits/stdc++.h>

using namespace std;
/// 15:26

const int Nmax = 2e5 + 5, inf = 2e9;

int n, m, A, B, S, D, i, x, y;
int dist1[Nmax], dist2[Nmax];
vector<int> v[Nmax];

bool adv(int &node)
{
    for(auto it : v[node])
        if(dist1[it] == dist1[node] - 1 && dist2[it] == dist2[node] - 1)
        {
            node = it;
            return 1;
        }
    return 0;
}

bool win(int tmp)
{
    int a, b, c, d;
    a = dist1[D], b = dist2[D];
    c = dist1[S] + tmp, d = dist2[S] + tmp;

    if(a < c || b < d) return 0;
    if(c < a && c < b) return 1;
    if(d < a && d < b) return 1;
    if(a == c && b > d) return 1;
    if(b == d && a > c) return 1;

    /// pana aici totul e frumos, iese pe hartie
    /// si acum vine cazul naspa, cireasa de pe tort
    /// avem a = c si b = d
    /// trebuie sa vedem care dintre aia doi ajunge primul la un nod care nu mai are continuare echidistanta fata de A si B
    /// cred ca nu se intersecteaza pe parcurs, cred...

    assert(a==b && c==d && a==b); /// sa ma aigur ca totusi n-am scapat ceva

    int i, ss = S, dd = D;
    for(i=1; i<=a; ++i)
    {
        if(!adv(dd)) return 1;
        if(i<=tmp) continue;
        if(!adv(ss)) return 0;
    }
    assert(0);
}

int solve()
{
    int st = 0, dr = n, mid;
    while(st <= dr)
    {
        mid = (st+dr)/2;
        if(!win(mid)) dr = mid-1;
            else st = mid+1;
    }
    return dr;
}

void calc(int node, int d[])
{
    int i;
    for(i=1; i<=n; ++i) d[i] = inf;

    queue<int> q;
    d[node] = 0;
    q.push(node);

    while(q.size())
    {
        node = q.front();
        q.pop();
        for(auto it : v[node])
            if(d[it] == inf)
            {
                d[it] = d[node] + 1;
                q.push(it);
            }
    }
}

int main()
{
 //   freopen("input", "r", stdin);
  //  freopen("output", "w", stdout);
    cin.sync_with_stdio(false);

    cin >> n >> m;
    cin >> S >> D >> A >> B;

    for(i=1; i<=m; ++i)
    {
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    calc(A, dist1);
    calc(B, dist2);

    cout << solve() << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5116 KB Output is correct
2 Runtime error 12 ms 10076 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Correct 7 ms 10100 KB Output is correct
4 Correct 7 ms 10204 KB Output is correct
5 Correct 6 ms 10204 KB Output is correct
6 Correct 6 ms 10204 KB Output is correct
7 Correct 8 ms 10204 KB Output is correct
8 Correct 6 ms 10204 KB Output is correct
9 Correct 8 ms 10204 KB Output is correct
10 Correct 5 ms 10204 KB Output is correct
11 Correct 5 ms 10204 KB Output is correct
12 Correct 6 ms 10204 KB Output is correct
13 Correct 6 ms 10224 KB Output is correct
14 Correct 6 ms 10224 KB Output is correct
15 Correct 6 ms 10224 KB Output is correct
16 Correct 6 ms 10224 KB Output is correct
17 Correct 6 ms 10224 KB Output is correct
18 Correct 6 ms 10348 KB Output is correct
19 Correct 6 ms 10348 KB Output is correct
20 Correct 6 ms 10352 KB Output is correct
21 Correct 6 ms 10352 KB Output is correct
22 Correct 7 ms 10352 KB Output is correct
23 Correct 6 ms 10352 KB Output is correct
24 Correct 7 ms 10352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 11788 KB Output is correct
2 Correct 46 ms 12428 KB Output is correct
3 Correct 28 ms 12428 KB Output is correct
4 Correct 55 ms 12556 KB Output is correct
5 Correct 34 ms 12556 KB Output is correct
6 Correct 37 ms 12556 KB Output is correct
7 Correct 37 ms 12556 KB Output is correct
8 Correct 37 ms 12556 KB Output is correct
9 Correct 57 ms 12556 KB Output is correct
10 Correct 244 ms 16872 KB Output is correct
11 Correct 60 ms 16872 KB Output is correct
12 Correct 77 ms 16872 KB Output is correct
13 Correct 61 ms 16872 KB Output is correct
14 Correct 58 ms 16872 KB Output is correct
15 Correct 72 ms 16872 KB Output is correct
16 Correct 86 ms 16872 KB Output is correct
17 Correct 63 ms 16872 KB Output is correct
18 Correct 71 ms 16872 KB Output is correct
19 Correct 114 ms 16872 KB Output is correct
20 Correct 289 ms 18460 KB Output is correct
21 Correct 126 ms 18460 KB Output is correct
22 Correct 100 ms 18460 KB Output is correct
23 Runtime error 107 ms 22676 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Correct 139 ms 22676 KB Output is correct
25 Correct 131 ms 22676 KB Output is correct
26 Runtime error 110 ms 22676 KB Execution killed with signal 11 (could be triggered by violating memory limits)
27 Correct 121 ms 22676 KB Output is correct
28 Correct 130 ms 22676 KB Output is correct
29 Correct 164 ms 22676 KB Output is correct
30 Correct 311 ms 24872 KB Output is correct
31 Correct 130 ms 24872 KB Output is correct
32 Correct 120 ms 24872 KB Output is correct
33 Runtime error 117 ms 24872 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Correct 141 ms 24872 KB Output is correct
35 Correct 140 ms 24872 KB Output is correct
36 Correct 134 ms 24872 KB Output is correct
37 Correct 145 ms 24872 KB Output is correct
38 Correct 180 ms 24872 KB Output is correct
39 Correct 226 ms 24872 KB Output is correct
40 Correct 253 ms 25768 KB Output is correct
41 Correct 319 ms 27960 KB Output is correct