#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==c && b==d); /// 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
5092 KB |
Output is correct |
3 |
Correct |
7 ms |
5168 KB |
Output is correct |
4 |
Correct |
6 ms |
5168 KB |
Output is correct |
5 |
Correct |
7 ms |
5344 KB |
Output is correct |
6 |
Correct |
6 ms |
5344 KB |
Output is correct |
7 |
Correct |
6 ms |
5344 KB |
Output is correct |
8 |
Correct |
6 ms |
5344 KB |
Output is correct |
9 |
Correct |
6 ms |
5344 KB |
Output is correct |
10 |
Correct |
7 ms |
5344 KB |
Output is correct |
11 |
Correct |
6 ms |
5344 KB |
Output is correct |
12 |
Correct |
7 ms |
5356 KB |
Output is correct |
13 |
Correct |
7 ms |
5356 KB |
Output is correct |
14 |
Correct |
6 ms |
5356 KB |
Output is correct |
15 |
Correct |
7 ms |
5356 KB |
Output is correct |
16 |
Correct |
7 ms |
5356 KB |
Output is correct |
17 |
Correct |
7 ms |
5484 KB |
Output is correct |
18 |
Correct |
8 ms |
5484 KB |
Output is correct |
19 |
Correct |
8 ms |
5484 KB |
Output is correct |
20 |
Correct |
7 ms |
5484 KB |
Output is correct |
21 |
Correct |
6 ms |
5484 KB |
Output is correct |
22 |
Correct |
6 ms |
5484 KB |
Output is correct |
23 |
Correct |
7 ms |
5484 KB |
Output is correct |
24 |
Correct |
7 ms |
5484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
6908 KB |
Output is correct |
2 |
Correct |
48 ms |
7548 KB |
Output is correct |
3 |
Correct |
40 ms |
7548 KB |
Output is correct |
4 |
Correct |
46 ms |
7676 KB |
Output is correct |
5 |
Correct |
43 ms |
7676 KB |
Output is correct |
6 |
Correct |
52 ms |
7676 KB |
Output is correct |
7 |
Correct |
31 ms |
7676 KB |
Output is correct |
8 |
Correct |
39 ms |
7676 KB |
Output is correct |
9 |
Correct |
48 ms |
7676 KB |
Output is correct |
10 |
Correct |
193 ms |
12108 KB |
Output is correct |
11 |
Correct |
62 ms |
12108 KB |
Output is correct |
12 |
Correct |
85 ms |
12108 KB |
Output is correct |
13 |
Correct |
71 ms |
12108 KB |
Output is correct |
14 |
Correct |
71 ms |
12108 KB |
Output is correct |
15 |
Correct |
110 ms |
12108 KB |
Output is correct |
16 |
Correct |
110 ms |
12108 KB |
Output is correct |
17 |
Correct |
75 ms |
12108 KB |
Output is correct |
18 |
Correct |
105 ms |
12108 KB |
Output is correct |
19 |
Correct |
131 ms |
12108 KB |
Output is correct |
20 |
Correct |
239 ms |
13564 KB |
Output is correct |
21 |
Correct |
129 ms |
13564 KB |
Output is correct |
22 |
Correct |
105 ms |
13564 KB |
Output is correct |
23 |
Runtime error |
185 ms |
22652 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
24 |
Correct |
116 ms |
22652 KB |
Output is correct |
25 |
Correct |
134 ms |
22652 KB |
Output is correct |
26 |
Runtime error |
101 ms |
22652 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
27 |
Correct |
119 ms |
22652 KB |
Output is correct |
28 |
Correct |
127 ms |
22652 KB |
Output is correct |
29 |
Correct |
166 ms |
22652 KB |
Output is correct |
30 |
Correct |
250 ms |
24844 KB |
Output is correct |
31 |
Correct |
143 ms |
24844 KB |
Output is correct |
32 |
Correct |
141 ms |
24844 KB |
Output is correct |
33 |
Correct |
137 ms |
24844 KB |
Output is correct |
34 |
Correct |
174 ms |
24844 KB |
Output is correct |
35 |
Correct |
131 ms |
24844 KB |
Output is correct |
36 |
Correct |
139 ms |
24844 KB |
Output is correct |
37 |
Correct |
151 ms |
24844 KB |
Output is correct |
38 |
Correct |
163 ms |
24844 KB |
Output is correct |
39 |
Correct |
170 ms |
24844 KB |
Output is correct |
40 |
Correct |
250 ms |
24952 KB |
Output is correct |
41 |
Correct |
334 ms |
27044 KB |
Output is correct |