답안 #52332

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52332 2018-06-25T12:46:50 Z Alexa2001 007 (CEOI14_007) C++17
24 / 100
397 ms 113448 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;
    for(i=1; i<=a; ++i)
    {
        if(!adv(D)) return 1;
        if(i<=tmp) continue;
        if(!adv(S)) 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Runtime error 12 ms 10096 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Correct 6 ms 10096 KB Output is correct
4 Correct 6 ms 10148 KB Output is correct
5 Partially correct 6 ms 10148 KB Partially correct
6 Correct 7 ms 10180 KB Output is correct
7 Correct 6 ms 10212 KB Output is correct
8 Partially correct 6 ms 10292 KB Partially correct
9 Correct 6 ms 10300 KB Output is correct
10 Correct 6 ms 10300 KB Output is correct
11 Correct 6 ms 10300 KB Output is correct
12 Correct 6 ms 10328 KB Output is correct
13 Correct 6 ms 10332 KB Output is correct
14 Correct 6 ms 10332 KB Output is correct
15 Correct 6 ms 10332 KB Output is correct
16 Correct 6 ms 10368 KB Output is correct
17 Correct 6 ms 10368 KB Output is correct
18 Incorrect 6 ms 10368 KB Output isn't correct
19 Correct 6 ms 10516 KB Output is correct
20 Correct 6 ms 10516 KB Output is correct
21 Correct 6 ms 10516 KB Output is correct
22 Correct 6 ms 10528 KB Output is correct
23 Correct 6 ms 10528 KB Output is correct
24 Partially correct 6 ms 10528 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 12588 KB Output is correct
2 Partially correct 42 ms 13960 KB Partially correct
3 Correct 31 ms 13960 KB Output is correct
4 Correct 44 ms 15212 KB Output is correct
5 Correct 29 ms 15212 KB Output is correct
6 Correct 30 ms 15640 KB Output is correct
7 Correct 33 ms 16264 KB Output is correct
8 Correct 34 ms 16924 KB Output is correct
9 Correct 48 ms 18236 KB Output is correct
10 Correct 181 ms 27864 KB Output is correct
11 Correct 61 ms 27864 KB Output is correct
12 Correct 82 ms 28196 KB Output is correct
13 Correct 69 ms 28764 KB Output is correct
14 Correct 55 ms 29192 KB Output is correct
15 Correct 86 ms 31852 KB Output is correct
16 Correct 87 ms 33616 KB Output is correct
17 Correct 76 ms 34388 KB Output is correct
18 Correct 76 ms 35644 KB Output is correct
19 Correct 123 ms 39364 KB Output is correct
20 Partially correct 233 ms 47652 KB Partially correct
21 Correct 118 ms 47680 KB Output is correct
22 Correct 103 ms 48552 KB Output is correct
23 Runtime error 118 ms 57584 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Correct 120 ms 59328 KB Output is correct
25 Correct 152 ms 61012 KB Output is correct
26 Runtime error 106 ms 62340 KB Execution killed with signal 11 (could be triggered by violating memory limits)
27 Correct 117 ms 64448 KB Output is correct
28 Correct 237 ms 66424 KB Output is correct
29 Correct 216 ms 70408 KB Output is correct
30 Incorrect 265 ms 78268 KB Output isn't correct
31 Correct 219 ms 78992 KB Output is correct
32 Correct 123 ms 79928 KB Output is correct
33 Runtime error 118 ms 83136 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Correct 144 ms 85720 KB Output is correct
35 Correct 149 ms 87436 KB Output is correct
36 Correct 121 ms 89868 KB Output is correct
37 Correct 156 ms 93108 KB Output is correct
38 Correct 206 ms 95360 KB Output is correct
39 Correct 190 ms 97824 KB Output is correct
40 Incorrect 236 ms 103956 KB Output isn't correct
41 Correct 397 ms 113448 KB Output is correct