이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
vector <vector <pii>> g;
int n, m;
ll len;
void find_pair(int N, vector <int> U, vector<int> V, int light, int heavy){
n = N; m = sz(U);
g.resize(n);
for(int i = 0; i < m; i++){
g[U[i]].pb(mp(V[i], i));
g[V[i]].pb(mp(U[i], i));
}
vector <ll> dist(n);
vector <int> q(m), edges;
queue <int> K;
len = ask(q)/light;
for(auto &to : dist) to = 1e18;
for(auto &to : q) to = 1;
int l = 0, r = m-1;
int s, t;
int mn = 2e9;
while(l <= r){
int mid = (l+r) >> 1;
for(int i = 0; i <= mid; i++) q[i] = 0;
auto ans = ask(q);
for(int i = 0; i <= mid; i++) q[i] = 1;
if(ans%light == 0 && ans/light == len){
mn = min(mn, mid);
r = mid-1;
}
else{
l = mid+1;
}
}
dist[V[mn]] = 0;
K.push(V[mn]);
while(!K.empty()){
auto v = K.front(); K.pop();
for(auto to : g[v]){
if(dist[to.first] > dist[v]+1){
dist[to.first] = dist[v]+1;
K.push(to.first);
edges.pb(to.second);
}
}
}
for(auto &to : q) to = 1;
l = 0; r = sz(edges)-1; mn = 2e9;
while(l <= r){
int mid = (l+r) >> 1;
for(int i = 0; i <= mid; i++) q[edges[i]] = 0;
auto ans = ask(q);
for(int i = 0; i <= mid; i++) q[edges[i]] = 1;
if(ans%light == 0 && ans/light == len){
mn = min(mn, mid);
r = mid-1;
}
else{
l = mid+1;
}
}
auto rebro = edges[mn];
if(dist[U[rebro]] > dist[V[rebro]]){
s = U[rebro];
}
else{
s = V[rebro];
}
edges.clear();
for(auto &to : dist) to = 1e18;
dist[s] = 0;
K.push(s);
while(!K.empty()){
auto v = K.front(); K.pop();
for(auto to : g[v]){
if(dist[to.first] > dist[v]+1){
dist[to.first] = dist[v]+1;
K.push(to.first);
edges.pb(to.second);
}
}
}
for(auto &to : q) to = 1;
l = 0; r = sz(edges)-1;
mn = 2e9;
while(l <= r){
int mid = (l+r) >> 1;
for(int i = 0; i <= mid; i++) q[edges[i]] = 0;
auto ans = ask(q);
for(int i = 0; i <= mid; i++) q[edges[i]] = 1;
if(ans%light == 0 && ans/light == len){
mn = min(mn, mid);
r = mid-1;
}
else{
l = mid+1;
}
}
rebro = edges[mn];
if(dist[U[rebro]] > dist[V[rebro]]){
t = U[rebro];
}
else{
t = V[rebro];
}
answer(s, t);
}
/*
4 3
7 13
0 3
0 1
1 2
2 3
15 14
7 13
3 12
0 1
1 3
1 4
3 8
3 9
4 10
4 11
10 13
11 14
0 2
2 5
2 6
2 7
7 12
15 16
7 13
3 12
0 1
1 3
1 4
3 8
3 9
4 10
4 11
10 13
11 14
0 2
2 5
2 6
2 7
7 12
3 10
3 4
7 9
1 2
0 1
0 3
1 2
0 4
0 5
5 6
0 2
6 1
3 1
4 1
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |