#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 25;
vector <pair <int, int>> adj[MAXN];
vector <int> adj2[MAXN];
bool vis[MAXN];
int deg[MAXN];
vector <int> t;
int n;
void init (int N, int m, vector <int> u, vector <int> v, vector <int> w) {
t = w; sort(t.begin(), t.end());
n = N;
for (int i = 0; i < m; i++) {
adj[u[i]].push_back({v[i], w[i]});
adj[v[i]].push_back({u[i], w[i]});
}
}
bool flag;
int cnt2 = 0;
void dfs (int pos) {
vis[pos] = 1;
flag |= deg[pos] > 2;
//cout << pos << " " << deg[pos] << '\n';
cnt2 += deg[pos] == 1;
for (auto j : adj2[pos]) {
if (!vis[j]) {
dfs(j);
}
}
}
int getMinimumFuelCapacity (int x, int y) {
int l = 0, r = (int)t.size() - 1, ans = -1;
while (l <= r) {
int mid = (l + r) >> 1;
for (int i = 0; i < n; i++) {
adj2[i].clear(); vis[i] = 0; deg[i] = 0;
for (auto [h, z] : adj[i]) {
if (z <= t[mid]) {
adj2[i].push_back(h);
deg[i]++;
}
}
//cout << (int)adj[i].size() << " " << deg[i] << ": " << (int)adj2[i].size() << '\n';
}
flag = 0; cnt2 = 0;
dfs(x);
//cout << flag << " " << cnt2 << '\n';
if (!vis[y] || (!flag && cnt2 == 2)) {
l = mid + 1;
} else {
r = mid - 1; ans = mid;
}
}
return ans == -1 ? -1 : t[ans];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5208 KB |
Output is correct |
2 |
Correct |
1 ms |
5212 KB |
Output is correct |
3 |
Correct |
1 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Correct |
2 ms |
5468 KB |
Output is correct |
6 |
Correct |
2 ms |
5536 KB |
Output is correct |
7 |
Correct |
2 ms |
5468 KB |
Output is correct |
8 |
Correct |
3 ms |
5580 KB |
Output is correct |
9 |
Correct |
76 ms |
15036 KB |
Output is correct |
10 |
Correct |
147 ms |
16868 KB |
Output is correct |
11 |
Correct |
186 ms |
16844 KB |
Output is correct |
12 |
Correct |
226 ms |
17364 KB |
Output is correct |
13 |
Correct |
379 ms |
17672 KB |
Output is correct |
14 |
Execution timed out |
2013 ms |
15544 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5208 KB |
Output is correct |
2 |
Correct |
1 ms |
5212 KB |
Output is correct |
3 |
Execution timed out |
2013 ms |
18308 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5208 KB |
Output is correct |
2 |
Correct |
1 ms |
5212 KB |
Output is correct |
3 |
Correct |
1 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Correct |
2 ms |
5468 KB |
Output is correct |
6 |
Correct |
2 ms |
5536 KB |
Output is correct |
7 |
Correct |
2 ms |
5468 KB |
Output is correct |
8 |
Correct |
3 ms |
5580 KB |
Output is correct |
9 |
Correct |
1 ms |
5212 KB |
Output is correct |
10 |
Correct |
2 ms |
5468 KB |
Output is correct |
11 |
Correct |
3 ms |
5444 KB |
Output is correct |
12 |
Correct |
4 ms |
5464 KB |
Output is correct |
13 |
Correct |
2 ms |
5468 KB |
Output is correct |
14 |
Correct |
2 ms |
5464 KB |
Output is correct |
15 |
Correct |
2 ms |
5468 KB |
Output is correct |
16 |
Correct |
2 ms |
5464 KB |
Output is correct |
17 |
Correct |
2 ms |
5464 KB |
Output is correct |
18 |
Correct |
2 ms |
5468 KB |
Output is correct |
19 |
Correct |
3 ms |
5544 KB |
Output is correct |
20 |
Correct |
2 ms |
5468 KB |
Output is correct |
21 |
Correct |
3 ms |
5468 KB |
Output is correct |
22 |
Correct |
3 ms |
5468 KB |
Output is correct |
23 |
Correct |
2 ms |
5464 KB |
Output is correct |
24 |
Correct |
3 ms |
5464 KB |
Output is correct |
25 |
Correct |
3 ms |
5436 KB |
Output is correct |
26 |
Correct |
3 ms |
5468 KB |
Output is correct |
27 |
Correct |
2 ms |
5464 KB |
Output is correct |
28 |
Correct |
4 ms |
5468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
5212 KB |
Output is correct |
2 |
Correct |
2 ms |
5208 KB |
Output is correct |
3 |
Correct |
1 ms |
5212 KB |
Output is correct |
4 |
Correct |
1 ms |
5212 KB |
Output is correct |
5 |
Correct |
2 ms |
5468 KB |
Output is correct |
6 |
Correct |
2 ms |
5468 KB |
Output is correct |
7 |
Correct |
2 ms |
5536 KB |
Output is correct |
8 |
Correct |
2 ms |
5468 KB |
Output is correct |
9 |
Correct |
3 ms |
5580 KB |
Output is correct |
10 |
Correct |
76 ms |
15036 KB |
Output is correct |
11 |
Correct |
147 ms |
16868 KB |
Output is correct |
12 |
Correct |
186 ms |
16844 KB |
Output is correct |
13 |
Correct |
226 ms |
17364 KB |
Output is correct |
14 |
Correct |
379 ms |
17672 KB |
Output is correct |
15 |
Correct |
2 ms |
5468 KB |
Output is correct |
16 |
Correct |
3 ms |
5444 KB |
Output is correct |
17 |
Correct |
4 ms |
5464 KB |
Output is correct |
18 |
Correct |
2 ms |
5468 KB |
Output is correct |
19 |
Correct |
2 ms |
5464 KB |
Output is correct |
20 |
Correct |
2 ms |
5468 KB |
Output is correct |
21 |
Correct |
2 ms |
5464 KB |
Output is correct |
22 |
Correct |
2 ms |
5464 KB |
Output is correct |
23 |
Correct |
2 ms |
5468 KB |
Output is correct |
24 |
Correct |
3 ms |
5544 KB |
Output is correct |
25 |
Correct |
2 ms |
5468 KB |
Output is correct |
26 |
Correct |
3 ms |
5468 KB |
Output is correct |
27 |
Correct |
3 ms |
5468 KB |
Output is correct |
28 |
Correct |
2 ms |
5464 KB |
Output is correct |
29 |
Correct |
3 ms |
5464 KB |
Output is correct |
30 |
Correct |
3 ms |
5436 KB |
Output is correct |
31 |
Correct |
3 ms |
5468 KB |
Output is correct |
32 |
Correct |
2 ms |
5464 KB |
Output is correct |
33 |
Correct |
4 ms |
5468 KB |
Output is correct |
34 |
Correct |
12 ms |
6744 KB |
Output is correct |
35 |
Correct |
166 ms |
17604 KB |
Output is correct |
36 |
Correct |
152 ms |
16584 KB |
Output is correct |
37 |
Correct |
162 ms |
15796 KB |
Output is correct |
38 |
Correct |
254 ms |
15324 KB |
Output is correct |
39 |
Correct |
177 ms |
15312 KB |
Output is correct |
40 |
Correct |
192 ms |
14400 KB |
Output is correct |
41 |
Correct |
176 ms |
17136 KB |
Output is correct |
42 |
Correct |
218 ms |
17084 KB |
Output is correct |
43 |
Correct |
236 ms |
17080 KB |
Output is correct |
44 |
Correct |
266 ms |
16112 KB |
Output is correct |
45 |
Correct |
435 ms |
18940 KB |
Output is correct |
46 |
Correct |
178 ms |
16832 KB |
Output is correct |
47 |
Correct |
277 ms |
15544 KB |
Output is correct |
48 |
Correct |
335 ms |
15928 KB |
Output is correct |
49 |
Correct |
89 ms |
17236 KB |
Output is correct |
50 |
Correct |
98 ms |
14420 KB |
Output is correct |
51 |
Correct |
299 ms |
17112 KB |
Output is correct |
52 |
Correct |
464 ms |
21496 KB |
Output is correct |
53 |
Correct |
437 ms |
21264 KB |
Output is correct |
54 |
Correct |
496 ms |
23744 KB |
Output is correct |
55 |
Correct |
270 ms |
18312 KB |
Output is correct |
56 |
Correct |
579 ms |
21360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5208 KB |
Output is correct |
2 |
Correct |
1 ms |
5212 KB |
Output is correct |
3 |
Correct |
1 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Correct |
2 ms |
5468 KB |
Output is correct |
6 |
Correct |
2 ms |
5536 KB |
Output is correct |
7 |
Correct |
2 ms |
5468 KB |
Output is correct |
8 |
Correct |
3 ms |
5580 KB |
Output is correct |
9 |
Correct |
76 ms |
15036 KB |
Output is correct |
10 |
Correct |
147 ms |
16868 KB |
Output is correct |
11 |
Correct |
186 ms |
16844 KB |
Output is correct |
12 |
Correct |
226 ms |
17364 KB |
Output is correct |
13 |
Correct |
379 ms |
17672 KB |
Output is correct |
14 |
Execution timed out |
2013 ms |
15544 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
5212 KB |
Output is correct |
2 |
Correct |
2 ms |
5208 KB |
Output is correct |
3 |
Correct |
1 ms |
5212 KB |
Output is correct |
4 |
Correct |
1 ms |
5212 KB |
Output is correct |
5 |
Correct |
2 ms |
5468 KB |
Output is correct |
6 |
Correct |
2 ms |
5468 KB |
Output is correct |
7 |
Correct |
2 ms |
5536 KB |
Output is correct |
8 |
Correct |
2 ms |
5468 KB |
Output is correct |
9 |
Correct |
3 ms |
5580 KB |
Output is correct |
10 |
Correct |
76 ms |
15036 KB |
Output is correct |
11 |
Correct |
147 ms |
16868 KB |
Output is correct |
12 |
Correct |
186 ms |
16844 KB |
Output is correct |
13 |
Correct |
226 ms |
17364 KB |
Output is correct |
14 |
Correct |
379 ms |
17672 KB |
Output is correct |
15 |
Execution timed out |
2013 ms |
15544 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |