#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
template<typename T> int SIZE(T (&t)){ return t.size(); } template<typename T, size_t N> int SIZE(T (&t)[N]){ return N; } string to_string(char t){ return "'" + string({t}) + "'"; } string to_string(bool t){ return t ? "true" : "false"; } string to_string(const string &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)), _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += t[i]; } return '"' + ret + '"'; } string to_string(const char* t){ string ret(t); return to_string(ret); } template<size_t N> string to_string(const bitset<N> &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)); i <= min(x2,SIZE(t)-1); ++i){ ret += t[i] + '0'; } return to_string(ret); } template<typename T, typename... Coords> string to_string(const T (&t), int x1=0, int x2=1e9, Coords... C); template<typename T, typename S> string to_string(const pair<T, S> &t){ return "(" + to_string(t.first) + ", " + to_string(t.second) + ")"; } template<typename T, typename... Coords> string to_string(const T (&t), int x1, int x2, Coords... C){ string ret = "["; x1 = min(x1, SIZE(t)); auto e = begin(t); advance(e,x1); for(int i = x1, _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += to_string(*e, C...) + (i != _i ? ", " : ""); e = next(e); } return ret + "]"; } template<int Index, typename... Ts> struct print_tuple{ string operator() (const tuple<Ts...>& t) { string ret = print_tuple<Index - 1, Ts...>{}(t); ret += (Index ? ", " : ""); return ret + to_string(get<Index>(t)); } }; template<typename... Ts> struct print_tuple<0, Ts...> { string operator() (const tuple<Ts...>& t) { return to_string(get<0>(t)); } }; template<typename... Ts> string to_string(const tuple<Ts...>& t) { const auto Size = tuple_size<tuple<Ts...>>::value; return print_tuple<Size - 1, Ts...>{}(t); } void dbgr(){;} template<typename Heads, typename... Tails> void dbgr(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgr(T...); } void dbgs(){;} template<typename Heads, typename... Tails> void dbgs(Heads H, Tails... T){ cout << H << " "; dbgs(T...); }
#define dbgv(...) cout << to_string(__VA_ARGS__) << endl;
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgv(__VA_ARGS__);
#define dbgr(...) dbgr(__VA_ARGS__); cout << endl;
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgr(__VA_ARGS__);
const int N = 1e5 + 5;
const int M = 2e5 + 5;
const int MAXA = 1e9 + 7;
int n, m;
array<int, 3> edge[M];
vector <int> a[N];
int ma = 0;
bool vis[N];
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n = N; m = M;
for(int i = 0; i < m; ++i){
edge[i] = {U[i], V[i], W[i]};
ma = max(ma, W[i]);
//a[U[i]].push_back({V[i], W[i]});
//a[V[i]].push_back({U[i], W[i]});
}
}
void bfs(vector <int> &d, int u, int ban = -1){
queue<int> q;
q.push(u);
while (!q.empty()){
int u = q.front(); q.pop();
for(int i : a[u]){
if (i == ban) continue;
if (d[i] == MAXA){
d[i] = d[u] + 1;
q.push(i);
}
}
}
}
bool f(int mid, int X, int Y){
for(int i = 0; i < n; ++i) a[i].clear(), vis[i] = false;
for(int i = 0; i < m; ++i){
if (edge[i][2] <= mid) {
a[edge[i][0]].push_back(edge[i][1]);
a[edge[i][1]].push_back(edge[i][0]);
}
}
vector <int> d(n, MAXA);
d[X] = 0; bfs(d, X);
vector <int> dx(n, MAXA), dy(n, MAXA);
dx[X] = 0; bfs(dx, X, Y);
dy[Y] = 0; bfs(dy, Y, X);
//dbg(dx, 0, n - 1);
//dbg(dy, 0, n - 1);
int disxy = d[Y];
if (disxy >= MAXA) return false;
vector <bool> f(disxy + 1, 0);
for(int i = 0; i < n; ++i){
if (dx[i] == MAXA || dy[i] == MAXA) continue;
if (dx[i] + dy[i] != disxy) return true;
if (f[dx[i]]) return true;
f[dx[i]] = true;
}
return false;
}
int getMinimumFuelCapacity(int X, int Y) {
int l = 0, r = MAXA;
while (l + 1 < r){
int mid = (l + r) >> 1;
if (f(mid, X, Y)) r = mid;
else l = mid;
}
if (r == MAXA) r = -1;
return r;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
3 ms |
2644 KB |
Output is correct |
4 |
Correct |
5 ms |
2644 KB |
Output is correct |
5 |
Correct |
8 ms |
2644 KB |
Output is correct |
6 |
Correct |
8 ms |
2736 KB |
Output is correct |
7 |
Correct |
9 ms |
2756 KB |
Output is correct |
8 |
Correct |
10 ms |
2748 KB |
Output is correct |
9 |
Correct |
504 ms |
8468 KB |
Output is correct |
10 |
Correct |
1461 ms |
9980 KB |
Output is correct |
11 |
Execution timed out |
2029 ms |
9788 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Execution timed out |
2072 ms |
12404 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
3 ms |
2644 KB |
Output is correct |
4 |
Correct |
5 ms |
2644 KB |
Output is correct |
5 |
Correct |
8 ms |
2644 KB |
Output is correct |
6 |
Correct |
8 ms |
2736 KB |
Output is correct |
7 |
Correct |
9 ms |
2756 KB |
Output is correct |
8 |
Correct |
10 ms |
2748 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
6 ms |
2644 KB |
Output is correct |
11 |
Correct |
10 ms |
2744 KB |
Output is correct |
12 |
Correct |
12 ms |
2748 KB |
Output is correct |
13 |
Correct |
8 ms |
2680 KB |
Output is correct |
14 |
Correct |
8 ms |
2740 KB |
Output is correct |
15 |
Incorrect |
8 ms |
2644 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
3 ms |
2644 KB |
Output is correct |
5 |
Correct |
5 ms |
2644 KB |
Output is correct |
6 |
Correct |
8 ms |
2644 KB |
Output is correct |
7 |
Correct |
8 ms |
2736 KB |
Output is correct |
8 |
Correct |
9 ms |
2756 KB |
Output is correct |
9 |
Correct |
10 ms |
2748 KB |
Output is correct |
10 |
Correct |
504 ms |
8468 KB |
Output is correct |
11 |
Correct |
1461 ms |
9980 KB |
Output is correct |
12 |
Execution timed out |
2029 ms |
9788 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
3 ms |
2644 KB |
Output is correct |
4 |
Correct |
5 ms |
2644 KB |
Output is correct |
5 |
Correct |
8 ms |
2644 KB |
Output is correct |
6 |
Correct |
8 ms |
2736 KB |
Output is correct |
7 |
Correct |
9 ms |
2756 KB |
Output is correct |
8 |
Correct |
10 ms |
2748 KB |
Output is correct |
9 |
Correct |
504 ms |
8468 KB |
Output is correct |
10 |
Correct |
1461 ms |
9980 KB |
Output is correct |
11 |
Execution timed out |
2029 ms |
9788 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
3 ms |
2644 KB |
Output is correct |
5 |
Correct |
5 ms |
2644 KB |
Output is correct |
6 |
Correct |
8 ms |
2644 KB |
Output is correct |
7 |
Correct |
8 ms |
2736 KB |
Output is correct |
8 |
Correct |
9 ms |
2756 KB |
Output is correct |
9 |
Correct |
10 ms |
2748 KB |
Output is correct |
10 |
Correct |
504 ms |
8468 KB |
Output is correct |
11 |
Correct |
1461 ms |
9980 KB |
Output is correct |
12 |
Execution timed out |
2029 ms |
9788 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |