이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
const int dydis = 1e5 + 10;
vector<pair<int, int> > gr[dydis];
int n, m;
long long light, heavy;
int tevas[dydis];
int dist[dydis];
int virs[dydis];
vector<pair<int, int> > brn;
int getLen(){
vector<int> st;
for(int i = 0; i < m; i++) st.push_back(0);
return 1ll * ask(st) / light;
}
void dfs(int v, int came = -1, int dst = 0){
dist[v] = dst;
for(auto x : gr[v]){
if(x.first == came) continue;
tevas[x.first] = v;
virs[x.first] = x.second;
dfs(x.first, v, dst+1);
}
}
vector<pair<int, int> > getInds(int v, int len){ // first - brianos indeksas, sec - virsunes
dfs(v, -1);
vector<pair<int, int> > ret;
for(int i = 0; i < n; i++){
if(dist[i] != len) continue;
ret.push_back({virs[i], i});
}
return ret;
}
pair<int, int> solveWhenHave(int v, int len){
vector<pair<int, int> > inds = getInds(v, len); // cia turetu visi buti blogi, isskyrus viena!
int l = 0; int r = inds.size()-1; int mid = -1; int kair = inds.size()-1;
vector<int> askk(m, 0);
long long turi = len * light;
while(l <= r){
mid = (l + r) / 2;
for(int i = 0; i <= mid; i++) askk[inds[i].first] = 1;
if(ask(askk) != turi){
r = mid-1;
kair = min(kair, mid);
}else{
l = mid+1;
}
for(int i = 0; i <= mid; i++) askk[inds[i].first] = 0;
}
return {v, inds[kair].second};
}
int findOne(int len){ //randa viena node'a
vector<pair<int, int> > inds;
for(int i = 0; i < (int) brn.size(); i++) inds.push_back({i, brn[i].first});
int l = 0; int r = inds.size()-1; int mid = -1; int kair = inds.size()-1;
vector<int> askk(m, 0);
long long turi = len * light;
while(l <= r){
mid = (l + r) / 2;
for(int i = 0; i <= mid; i++) askk[inds[i].first] = 1;
if(ask(askk) != turi){
r = mid-1;
kair = min(kair, mid);
}else{
l = mid+1;
}
for(int i = 0; i <= mid; i++) askk[inds[i].first] = 0;
}
return inds[kair].second;
}
int findFarthest(int v, int len){
dfs(v, -1);
return 0;
}
pair<int, int> solveEil(int len){
long long turi = light * len;
int leftmost = -1;
int l = 0; int r = n-1; int mid;
vector<int> st(m, 0);
while(l <= r){
mid = (l + r) / 2;
for(int i = 0; i <= mid; i++) st[i] = 1;
if(ask(st) == turi){
leftmost = max(leftmost, mid);
l = mid+1;
}else{
r = mid-1;
}
for(int i = 0; i <= mid; i++) st[i] = 0;
}
//cout << "leftmost = " << leftmost << endl;
int raitmost = n-1;
l = 0; r = n-1;
while(l <= r){
mid = (l + r) /2;
for(int i = mid; i <= n-1; i++) st[i] = 1;
if(ask(st) == turi){
raitmost = min(raitmost, mid);
r = mid-1;
}else{
l = mid+1;
}
for(int i = mid; i <= n-1; i++) st[i] = 0;
}
return {leftmost+1, raitmost};
}
/*
6 5
5 7
1 3
0 1
1 2
2 3
3 4
4 5
*/
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
n = N;
m = V.size();
light = A; heavy = B;
bool eile = 1;
for(int i = 0; i < m; i++){
gr[U[i]].push_back({V[i], i});
gr[V[i]].push_back({U[i], i});
brn.push_back({V[i], U[i]});
if(!(U[i] == i && V[i] == i+1)) eile = 0;
}
int len = getLen();
if(eile){
auto ret = solveEil(len);
answer(ret.first, ret.second);
return ;
}
//int vv = findOne(len);
//int uu = findFarthest(vv, len);
auto ans = solveWhenHave(0, len);
answer(ans.first, ans.second);
return ;
}
# | 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... |