#include <bits/stdc++.h>
#define ll long long
#define db long double
#define maxn 200005
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define IDB pair <db,int>
#define TII pair <treap*,treap*>
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x)
#include "highway.h"
using namespace std;
struct Interactive
{
ll f[maxn],n,m,i,u,v,k,s,t,A,B;
vector <int> U,V;
vector <II> a[maxn];
void Init(int _n,int _m,vector <int> _U,vector <int> _V,int _A,int _B,int _s,int _t)
{
n=_n; m=_m; U=_U; V=_V; A=_A; B=_B; s=_s; t=_t;
s++; t++;
for(i=0;i<m;i++) U[i]++,V[i]++;
}
ll Dijkstra(vector <int> status)
{
for(u=1;u<=n;u++) a[u].clear();
for(i=0;i<m;i++)
{
u=U[i]; v=V[i];
if(status[i]==0) k=A; else k=B;
a[u].push_back({ v,k }); a[v].push_back({ u,k });
}
for(u=1;u<=n;u++) f[u]=round(1e18);
set <II> h;
f[s]=0; h.insert({ 0,s });
while(h.size()>0)
{
int u=h.begin()->snd; h.erase(h.begin());
for(II adj:a[u])
{
int v=adj.fst,k=adj.snd;
if(f[v]>f[u]+k)
{
h.erase({ f[v],v });
f[v]=f[u]+k;
h.insert({ f[v],v });
}
}
}
return f[t];
}
} IR;
//ll ask(vector <int> Status) { return IR.Dijkstra(Status); }
//void answer(int s,int t) { cout<<s<<" "<<t<<'\n'; }
vector <int> Deleted;
vector <II> a[maxn];
ll best_cost,best_len;
int fx[maxn],fs[maxn],i,u,v,x,node[maxn],m;
void find_pair(int n,vector <int> U,vector <int> V,int A,int B)
{
m=U.size();
function <ll(vector <int>)> Try_to_Delete=[&](vector <int> Try)
{
vector <int> status(m);
for(int x:Deleted) status[x]=1;
for(int x:Try) status[x]=1;
return ask(status);
};
for(i=0;i<m;i++)
{
u=++U[i]; v=++V[i];
a[u].push_back({ v,i }); a[v].push_back({ u,i });
}
/////////////////////////////////////////////////////////////////////////////////////
//Find x
vector <int> vec;
best_cost=Try_to_Delete(vec);
best_len=best_cost/A;
int l=0,r=m-1,s,t;
while(l<r)
{
int mid=(l+r)>>1;
// cerr<<l<<" "<<r<<" "<<mid<<'\n';
vector <int> vec;
for(i=0;i<=mid;i++) vec.push_back(i);
if(Try_to_Delete(vec)>best_cost) r=mid; else l=mid+1;
}
// cerr<<l<<'\n';
for(i=0;i<l;i++) Deleted.push_back(i);
x=U[l];
////////////////////////////////////////////////////////////////////////////////////
//Find s
auto BFS=[&](int s,int f[])
{
for(int u=1;u<=n;u++) f[u]=round(1e9);
queue <int> q;
q.push(s); f[s]=0;
while(q.size()>0)
{
int u=q.front(); q.pop();
// if(s==2) cerr<<u<<'\n';
for(II adj:a[u])
{
int v=adj.fst,x=adj.snd;
if(f[v]>f[u]+1)
q.push(v),f[v]=f[u]+1;
}
}
};
// cerr<<x<<'\n';
BFS(x,fx);
for(i=1;i<=n;i++) node[i]=i;
sort(node+1,node+n+1,[&](int u,int v){ return fx[u]>fx[v]; });
// for(i=1;i<=n;i++) cerr<<node[i]<<'\n';
l=1; r=n;
while(l<r)
{
int mid=(l+r)>>1;
vector <int> vec;
for(i=1;i<=mid;i++)
{
u=node[i];
for(II adj:a[u])
if(fx[u]==fx[adj.fst]+1) vec.push_back(adj.snd);
}
if(Try_to_Delete(vec)>best_cost) r=mid; else l=mid+1;
}
s=node[l];
///////////////////////////////////////////////////////////////////////////////////////////
//Find t
BFS(s,fs);
// cerr<<fx[2]<<" "<<fx[4]<<" "<<fs[4]<<" "<<best_len<<'\n';
vector <int> candidates;
for(u=1;u<=n;u++)
if(fx[s]+fx[u]==fs[u] && fs[u]==best_len)
candidates.push_back(u);
l=0; r=candidates.size()-1;
while(l<r)
{
int mid=(l+r)>>1;
vector <int> vec;
for(i=0;i<=mid;i++)
{
u=candidates[i];
for(II adj:a[u])
if(fx[u]==fx[adj.fst]+1) vec.push_back(adj.snd);
}
if(Try_to_Delete(vec)>best_cost) r=mid; else l=mid+1;
}
t=candidates[l];
answer(s-1,t-1);
}
/*
int main()
{
freopen("highway.inp","r",stdin);
freopen("highway.out","w",stdout);
int n,m,A,B,s,t,u,v;
vector <int> U,V;
cin>>n>>m>>A>>B>>s>>t;
for(int i=0;i<m;i++) cin>>u>>v,U.push_back(u),V.push_back(v);
IR.Init(n,U,V,A,B,s,t);
find_pair(n,m,U,V,A,B);
}
*/
Compilation message
highway.cpp: In lambda function:
highway.cpp:118:31: warning: unused variable 'x' [-Wunused-variable]
118 | int v=adj.fst,x=adj.snd;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13400 KB |
Output is correct |
2 |
Correct |
3 ms |
13400 KB |
Output is correct |
3 |
Correct |
3 ms |
13400 KB |
Output is correct |
4 |
Correct |
4 ms |
13400 KB |
Output is correct |
5 |
Correct |
3 ms |
13400 KB |
Output is correct |
6 |
Correct |
3 ms |
13400 KB |
Output is correct |
7 |
Correct |
3 ms |
13400 KB |
Output is correct |
8 |
Correct |
3 ms |
13400 KB |
Output is correct |
9 |
Correct |
3 ms |
13588 KB |
Output is correct |
10 |
Correct |
3 ms |
13400 KB |
Output is correct |
11 |
Correct |
3 ms |
13588 KB |
Output is correct |
12 |
Correct |
3 ms |
13400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13648 KB |
Output is correct |
2 |
Correct |
15 ms |
14696 KB |
Output is correct |
3 |
Correct |
129 ms |
20840 KB |
Output is correct |
4 |
Correct |
111 ms |
20760 KB |
Output is correct |
5 |
Correct |
101 ms |
20832 KB |
Output is correct |
6 |
Correct |
147 ms |
20876 KB |
Output is correct |
7 |
Correct |
108 ms |
20880 KB |
Output is correct |
8 |
Correct |
132 ms |
21300 KB |
Output is correct |
9 |
Correct |
144 ms |
21540 KB |
Output is correct |
10 |
Correct |
106 ms |
21172 KB |
Output is correct |
11 |
Correct |
148 ms |
21292 KB |
Output is correct |
12 |
Correct |
134 ms |
20936 KB |
Output is correct |
13 |
Correct |
141 ms |
20940 KB |
Output is correct |
14 |
Correct |
162 ms |
20936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
14444 KB |
Output is correct |
2 |
Correct |
19 ms |
15220 KB |
Output is correct |
3 |
Correct |
41 ms |
16244 KB |
Output is correct |
4 |
Correct |
129 ms |
20732 KB |
Output is correct |
5 |
Correct |
125 ms |
20996 KB |
Output is correct |
6 |
Correct |
78 ms |
20364 KB |
Output is correct |
7 |
Correct |
97 ms |
21656 KB |
Output is correct |
8 |
Correct |
93 ms |
20508 KB |
Output is correct |
9 |
Correct |
97 ms |
21732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13652 KB |
Output is correct |
2 |
Correct |
14 ms |
14412 KB |
Output is correct |
3 |
Correct |
125 ms |
20284 KB |
Output is correct |
4 |
Correct |
171 ms |
21240 KB |
Output is correct |
5 |
Correct |
128 ms |
21412 KB |
Output is correct |
6 |
Correct |
136 ms |
21228 KB |
Output is correct |
7 |
Correct |
164 ms |
21304 KB |
Output is correct |
8 |
Correct |
187 ms |
21280 KB |
Output is correct |
9 |
Correct |
119 ms |
20888 KB |
Output is correct |
10 |
Correct |
135 ms |
21188 KB |
Output is correct |
11 |
Correct |
121 ms |
20968 KB |
Output is correct |
12 |
Correct |
122 ms |
20924 KB |
Output is correct |
13 |
Correct |
174 ms |
20900 KB |
Output is correct |
14 |
Correct |
120 ms |
20756 KB |
Output is correct |
15 |
Correct |
167 ms |
21596 KB |
Output is correct |
16 |
Correct |
138 ms |
21460 KB |
Output is correct |
17 |
Correct |
136 ms |
20868 KB |
Output is correct |
18 |
Correct |
144 ms |
21168 KB |
Output is correct |
19 |
Correct |
136 ms |
21444 KB |
Output is correct |
20 |
Correct |
185 ms |
21068 KB |
Output is correct |
21 |
Correct |
89 ms |
21420 KB |
Output is correct |
22 |
Correct |
95 ms |
21660 KB |
Output is correct |
23 |
Correct |
144 ms |
21776 KB |
Output is correct |
24 |
Correct |
129 ms |
20824 KB |
Output is correct |
25 |
Correct |
109 ms |
20640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
14440 KB |
Output is correct |
2 |
Correct |
18 ms |
14624 KB |
Output is correct |
3 |
Correct |
106 ms |
21400 KB |
Output is correct |
4 |
Correct |
139 ms |
22620 KB |
Output is correct |
5 |
Correct |
249 ms |
24960 KB |
Output is correct |
6 |
Correct |
210 ms |
24432 KB |
Output is correct |
7 |
Correct |
203 ms |
24644 KB |
Output is correct |
8 |
Correct |
146 ms |
24056 KB |
Output is correct |
9 |
Correct |
164 ms |
23624 KB |
Output is correct |
10 |
Correct |
143 ms |
24856 KB |
Output is correct |
11 |
Correct |
167 ms |
23800 KB |
Output is correct |
12 |
Correct |
201 ms |
24120 KB |
Output is correct |
13 |
Correct |
183 ms |
24000 KB |
Output is correct |
14 |
Correct |
218 ms |
24364 KB |
Output is correct |
15 |
Correct |
229 ms |
24552 KB |
Output is correct |
16 |
Correct |
149 ms |
23844 KB |
Output is correct |
17 |
Correct |
113 ms |
20680 KB |
Output is correct |
18 |
Correct |
91 ms |
21248 KB |
Output is correct |
19 |
Correct |
87 ms |
20716 KB |
Output is correct |
20 |
Correct |
105 ms |
20688 KB |
Output is correct |
21 |
Correct |
230 ms |
24760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
14556 KB |
Output is correct |
2 |
Correct |
20 ms |
14764 KB |
Output is correct |
3 |
Correct |
148 ms |
22108 KB |
Output is correct |
4 |
Correct |
155 ms |
22488 KB |
Output is correct |
5 |
Correct |
187 ms |
22688 KB |
Output is correct |
6 |
Correct |
224 ms |
24652 KB |
Output is correct |
7 |
Correct |
140 ms |
21976 KB |
Output is correct |
8 |
Correct |
151 ms |
22300 KB |
Output is correct |
9 |
Correct |
206 ms |
23300 KB |
Output is correct |
10 |
Correct |
205 ms |
24948 KB |
Output is correct |
11 |
Correct |
230 ms |
24068 KB |
Output is correct |
12 |
Correct |
200 ms |
24628 KB |
Output is correct |
13 |
Correct |
180 ms |
24156 KB |
Output is correct |
14 |
Correct |
127 ms |
24556 KB |
Output is correct |
15 |
Correct |
153 ms |
24064 KB |
Output is correct |
16 |
Correct |
121 ms |
24612 KB |
Output is correct |
17 |
Correct |
203 ms |
24116 KB |
Output is correct |
18 |
Correct |
151 ms |
24456 KB |
Output is correct |
19 |
Correct |
184 ms |
24324 KB |
Output is correct |
20 |
Correct |
212 ms |
24480 KB |
Output is correct |
21 |
Correct |
223 ms |
24328 KB |
Output is correct |
22 |
Correct |
184 ms |
24364 KB |
Output is correct |
23 |
Correct |
218 ms |
24060 KB |
Output is correct |
24 |
Correct |
234 ms |
24176 KB |
Output is correct |
25 |
Correct |
231 ms |
24480 KB |
Output is correct |
26 |
Correct |
182 ms |
24328 KB |
Output is correct |
27 |
Correct |
91 ms |
21068 KB |
Output is correct |
28 |
Correct |
123 ms |
21092 KB |
Output is correct |
29 |
Correct |
105 ms |
21448 KB |
Output is correct |
30 |
Correct |
132 ms |
20572 KB |
Output is correct |
31 |
Correct |
97 ms |
21232 KB |
Output is correct |
32 |
Correct |
98 ms |
20704 KB |
Output is correct |
33 |
Correct |
118 ms |
21572 KB |
Output is correct |
34 |
Correct |
87 ms |
20740 KB |
Output is correct |
35 |
Correct |
135 ms |
21320 KB |
Output is correct |
36 |
Correct |
84 ms |
20324 KB |
Output is correct |
37 |
Correct |
97 ms |
21188 KB |
Output is correct |
38 |
Correct |
101 ms |
21280 KB |
Output is correct |
39 |
Correct |
200 ms |
24188 KB |
Output is correct |
40 |
Correct |
219 ms |
24424 KB |
Output is correct |
41 |
Correct |
163 ms |
23732 KB |
Output is correct |
42 |
Correct |
205 ms |
24624 KB |
Output is correct |