#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 1000 * 1000 * 1000 * 2;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 1000 * 1000 + 7;
ll bas, A, B;
vector<int>ed[N], num[N];
vector<int> cnd;
int dis[N];
vector<int> cur;
bool vis[N];
vector<int> clr[2];
void DFS(int v, int cur)
{
clr[cur].pb(v); vis[v] = true;
for(int i = 0; i < (int)ed[v].size(); ++i)
if(!vis[ed[v][i]])
DFS(ed[v][i], cur ^ 1);
}
bool Question(int pos)
{
for(int i = pos; i < (int)cur.size(); ++i)
{
int v = cur[i];
for(int j = 0; j < (int)num[v].size(); ++j)
cnd[num[v][j]] = 1;
}
ll ans = ask(cnd);
for(int i = 0; i < (int)cnd.size(); ++i)
cnd[i] = 0;
return (ans > bas);
}
int BS()
{
int p = 0, k = (int)cur.size(), s;
while(p < k)
{
s = (p + k + 1) / 2;
if(Question(s))
p = s;
else
k = s - 1;
}
return cur[p];
}
void BFS(int s, int n)
{
int v; queue<int> q;
for(int i = 0; i <= n; ++i)
dis[i] = II;
dis[s] = 0;
q.push(s);
while(q.size() > 0)
{
v = q.front(); q.pop();
for(int i = 0; i < (int)ed[v].size(); ++i)
{
if(dis[ed[v][i]] > dis[v] + 1)
{
dis[ed[v][i]] = dis[v] + 1;
q.push(ed[v][i]);
}
}
}
}
void DoCur1(int n)
{
vector<pair<int, int>> hlp;
for(int i = 0; i < n; ++i)
hlp.pb(make_pair(dis[i], i));
sort(hlp.begin(), hlp.end());
cur.clear();
for(int i = 0; i < n; ++i)
cur.pb(hlp[i].nd);
/*cerr << "cur1 \n";
for(int i = 0; i < n; ++i)
cout << cur[i] << " ";
cout << "\n";*/
}
void DoCur2(int n, int il)
{
cur.clear();
for(int i = 0; i < n; ++i)
if(dis[i] == il)
cur.pb(i);
}
void find_pair(int N, vector<int> U, vector<int> V, int XA, int XB)
{
A = XA; B = XB;
int n = N;
for(int i = 0; i < (int)U.size(); ++i)
{
ed[U[i]].pb(V[i]); ed[V[i]].pb(U[i]);
num[U[i]].pb(i); num[V[i]].pb(i);
cnd.pb(0);
}
bas = ask(cnd);
DFS(0, 0);
if((int)clr[1].size() >= 1 && clr[1].size() < clr[0].size())
swap(clr[1], clr[0]);
cur = clr[0];
int mid = BS(), s, t;
//cerr << mid << "\n";
BFS(mid, n);
DoCur1(n);
s = BS();
//cerr << s << "\n";
BFS(s, n);
DoCur2(n, bas / A);
t = BS();
answer(s, t);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
50008 KB |
Output is correct |
2 |
Correct |
7 ms |
49868 KB |
Output is correct |
3 |
Correct |
7 ms |
49880 KB |
Output is correct |
4 |
Correct |
8 ms |
50008 KB |
Output is correct |
5 |
Correct |
7 ms |
50008 KB |
Output is correct |
6 |
Correct |
7 ms |
50048 KB |
Output is correct |
7 |
Correct |
7 ms |
50008 KB |
Output is correct |
8 |
Correct |
7 ms |
50008 KB |
Output is correct |
9 |
Correct |
7 ms |
50008 KB |
Output is correct |
10 |
Correct |
7 ms |
50008 KB |
Output is correct |
11 |
Correct |
7 ms |
50024 KB |
Output is correct |
12 |
Correct |
7 ms |
50048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
50008 KB |
Output is correct |
2 |
Correct |
17 ms |
51068 KB |
Output is correct |
3 |
Correct |
152 ms |
59876 KB |
Output is correct |
4 |
Correct |
130 ms |
59972 KB |
Output is correct |
5 |
Correct |
131 ms |
59720 KB |
Output is correct |
6 |
Correct |
120 ms |
59900 KB |
Output is correct |
7 |
Correct |
125 ms |
59668 KB |
Output is correct |
8 |
Correct |
151 ms |
60208 KB |
Output is correct |
9 |
Correct |
127 ms |
59708 KB |
Output is correct |
10 |
Correct |
126 ms |
59740 KB |
Output is correct |
11 |
Correct |
120 ms |
60968 KB |
Output is correct |
12 |
Correct |
124 ms |
61520 KB |
Output is correct |
13 |
Correct |
149 ms |
61188 KB |
Output is correct |
14 |
Correct |
142 ms |
60700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
51580 KB |
Output is correct |
2 |
Correct |
29 ms |
51352 KB |
Output is correct |
3 |
Correct |
42 ms |
52988 KB |
Output is correct |
4 |
Correct |
118 ms |
65312 KB |
Output is correct |
5 |
Correct |
87 ms |
65224 KB |
Output is correct |
6 |
Correct |
79 ms |
65176 KB |
Output is correct |
7 |
Correct |
101 ms |
65172 KB |
Output is correct |
8 |
Correct |
90 ms |
65128 KB |
Output is correct |
9 |
Correct |
89 ms |
65104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
50008 KB |
Output is correct |
2 |
Correct |
18 ms |
51032 KB |
Output is correct |
3 |
Correct |
97 ms |
57552 KB |
Output is correct |
4 |
Correct |
147 ms |
60056 KB |
Output is correct |
5 |
Correct |
139 ms |
59804 KB |
Output is correct |
6 |
Correct |
138 ms |
59904 KB |
Output is correct |
7 |
Correct |
167 ms |
57524 KB |
Output is correct |
8 |
Correct |
160 ms |
57512 KB |
Output is correct |
9 |
Correct |
154 ms |
57572 KB |
Output is correct |
10 |
Correct |
158 ms |
59836 KB |
Output is correct |
11 |
Correct |
143 ms |
60356 KB |
Output is correct |
12 |
Correct |
135 ms |
61608 KB |
Output is correct |
13 |
Correct |
137 ms |
60892 KB |
Output is correct |
14 |
Correct |
125 ms |
61476 KB |
Output is correct |
15 |
Correct |
131 ms |
59836 KB |
Output is correct |
16 |
Correct |
125 ms |
59984 KB |
Output is correct |
17 |
Correct |
110 ms |
61404 KB |
Output is correct |
18 |
Correct |
119 ms |
60900 KB |
Output is correct |
19 |
Correct |
121 ms |
59900 KB |
Output is correct |
20 |
Correct |
134 ms |
62004 KB |
Output is correct |
21 |
Correct |
103 ms |
60092 KB |
Output is correct |
22 |
Correct |
104 ms |
60096 KB |
Output is correct |
23 |
Correct |
118 ms |
60304 KB |
Output is correct |
24 |
Correct |
116 ms |
60880 KB |
Output is correct |
25 |
Correct |
122 ms |
64420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
51288 KB |
Output is correct |
2 |
Correct |
20 ms |
51288 KB |
Output is correct |
3 |
Correct |
130 ms |
61264 KB |
Output is correct |
4 |
Correct |
161 ms |
62056 KB |
Output is correct |
5 |
Correct |
185 ms |
63404 KB |
Output is correct |
6 |
Correct |
174 ms |
63408 KB |
Output is correct |
7 |
Correct |
190 ms |
63212 KB |
Output is correct |
8 |
Correct |
173 ms |
63276 KB |
Output is correct |
9 |
Correct |
129 ms |
56452 KB |
Output is correct |
10 |
Correct |
113 ms |
57480 KB |
Output is correct |
11 |
Correct |
115 ms |
57764 KB |
Output is correct |
12 |
Correct |
180 ms |
62572 KB |
Output is correct |
13 |
Correct |
164 ms |
63088 KB |
Output is correct |
14 |
Correct |
185 ms |
64056 KB |
Output is correct |
15 |
Correct |
170 ms |
63980 KB |
Output is correct |
16 |
Correct |
158 ms |
60076 KB |
Output is correct |
17 |
Correct |
120 ms |
60280 KB |
Output is correct |
18 |
Correct |
120 ms |
60756 KB |
Output is correct |
19 |
Correct |
117 ms |
60452 KB |
Output is correct |
20 |
Correct |
117 ms |
60636 KB |
Output is correct |
21 |
Correct |
189 ms |
62528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
51288 KB |
Output is correct |
2 |
Correct |
20 ms |
51280 KB |
Output is correct |
3 |
Correct |
146 ms |
61140 KB |
Output is correct |
4 |
Correct |
154 ms |
61644 KB |
Output is correct |
5 |
Correct |
159 ms |
61896 KB |
Output is correct |
6 |
Correct |
177 ms |
63360 KB |
Output is correct |
7 |
Correct |
150 ms |
61288 KB |
Output is correct |
8 |
Correct |
150 ms |
61828 KB |
Output is correct |
9 |
Correct |
159 ms |
62204 KB |
Output is correct |
10 |
Correct |
194 ms |
63420 KB |
Output is correct |
11 |
Correct |
192 ms |
63528 KB |
Output is correct |
12 |
Correct |
190 ms |
63432 KB |
Output is correct |
13 |
Correct |
112 ms |
57652 KB |
Output is correct |
14 |
Correct |
111 ms |
57480 KB |
Output is correct |
15 |
Correct |
111 ms |
57596 KB |
Output is correct |
16 |
Correct |
112 ms |
57440 KB |
Output is correct |
17 |
Correct |
119 ms |
57760 KB |
Output is correct |
18 |
Correct |
119 ms |
57496 KB |
Output is correct |
19 |
Correct |
163 ms |
63004 KB |
Output is correct |
20 |
Correct |
168 ms |
63524 KB |
Output is correct |
21 |
Correct |
189 ms |
63972 KB |
Output is correct |
22 |
Correct |
170 ms |
63940 KB |
Output is correct |
23 |
Correct |
184 ms |
64504 KB |
Output is correct |
24 |
Correct |
188 ms |
63932 KB |
Output is correct |
25 |
Correct |
189 ms |
64128 KB |
Output is correct |
26 |
Correct |
180 ms |
64156 KB |
Output is correct |
27 |
Correct |
114 ms |
60648 KB |
Output is correct |
28 |
Correct |
115 ms |
60360 KB |
Output is correct |
29 |
Correct |
117 ms |
60976 KB |
Output is correct |
30 |
Correct |
137 ms |
60428 KB |
Output is correct |
31 |
Correct |
141 ms |
60680 KB |
Output is correct |
32 |
Correct |
145 ms |
60068 KB |
Output is correct |
33 |
Correct |
133 ms |
60952 KB |
Output is correct |
34 |
Correct |
111 ms |
60412 KB |
Output is correct |
35 |
Correct |
126 ms |
60076 KB |
Output is correct |
36 |
Correct |
142 ms |
60468 KB |
Output is correct |
37 |
Correct |
125 ms |
60492 KB |
Output is correct |
38 |
Correct |
137 ms |
60312 KB |
Output is correct |
39 |
Correct |
180 ms |
62320 KB |
Output is correct |
40 |
Correct |
164 ms |
62360 KB |
Output is correct |
41 |
Correct |
151 ms |
62800 KB |
Output is correct |
42 |
Correct |
170 ms |
62352 KB |
Output is correct |