이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <highway.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define maxN 200010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <ll, ll>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;}
pii L[maxN];
int n, m, dis;
vector <pii> E[maxN];
vector <int> T[maxN];
int tap(vector <pii> v)
{
int sz = v.size();
int l = 0, r = sz-1, md, in = 0;
while(l <= r) {
md = (l+r)/2;
vector <int> arr;
for(int i = 0; i < m; i++) arr.pb(0);
for(int i = md; i < sz; i++)
for(auto h: T[v[i].ss])
arr[h] = 1;
int cur = ask(arr);
if(dis != cur) l = md+1, in = md;
else r = md-1;
}
return v[in].ss;
}
void find_pair(int N, vector <int> U, vector <int> V, int A, int B)
{
m = U.size(), n = N;
for(int i = 0; i < m; i++) {
E[U[i]].pb({V[i], i});
E[V[i]].pb({U[i], i});
}
vector <int> arr;
for(int i = 0; i < m; i++) arr.pb(0);
dis = ask(arr);
int l = 0, r = m-1, md, in = 0;
while(l <= r) {
md = (l+r)/2;
vector <int> arr;
for(int i = 0; i < m; i++) arr.pb((i <= md ? 1 : 0));
int cur = ask(arr);
if(dis != cur) r = md-1, in = md;
else l = md+1;
}
queue <pii> Q;
Q.push({U[in], 1});
Q.push({V[in], 2});
L[U[in]] = {0, 1};
L[V[in]] = {0, 2};
while(!Q.empty()) {
int nd = Q.front().ff;
int tp = Q.front().ss;
Q.pop();
for(auto i: E[nd]) {
int to = i.ff;
if(L[to].ss) continue;
L[to] = {L[nd].ff+1, tp};
Q.push({to, tp});
T[to].pb(i.ss);
}
}
vector <pii> v;
for(int i = 0; i < n; i++) if(L[i].ss == 1) v.pb({L[i].ff, i});
sort(v.begin(), v.end());
int s = tap(v);
v.clear();
for(int i = 0; i < n; i++) if(L[i].ss == 2) v.pb({L[i].ff, i});
sort(v.begin(), v.end());
int t = tap(v);
answer(s, t);
}
# | 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... |