이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# define LOCAL
# define sim template < class c
# define ris return * this
# define dor > debug & operator <<
# define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int gcd(int a, int b)
{
if(b) return gcd(b,a%b);
return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
long long ask(const std::vector<int> &w);
void answer(int s, int t);
# define int ll
vector<int32_t>askvec;
int dist;
vector<pair<int,int>>vec[1 << 18];
vector<int>euler;
int M,N;
vector<int>f;
int viz[1 << 18];
void root(int nod)
{
queue<int>Q;
Q.push(nod);
euler.clear();
for(int i = 0;i < M;i++) askvec[i] = 0;
for(int i = 0;i < N;i++) viz[i] = 0;
viz[nod] = 1;
f[nod] = -1;
while(sz(Q))
{
int x = Q.front();
Q.pop();
euler.pb(x);
for(auto it : vec[x])
{
if(!viz[it.first])
{
f[it.first] = it.second;
askvec[it.second] = 1;
Q.push(it.first);
viz[it.first] = 1;
}
}
}
for(int i = 0;i < M;i++) askvec[i] = !askvec[i];
}
int bs()
{
int l = 0;
int r = N - 1;
while(l < r)
{
int mid = l + r + 1 >> 1;
for(int i = mid;i < N;i++)
{
if(f[euler[i]] != -1) askvec[f[euler[i]]] = 1;
}
if(ask(askvec) != dist) l = mid;
else r = mid - 1;
for(int i = mid;i < N;i++)
{
if(f[euler[i]] != -1) askvec[f[euler[i]]] = 0;
}
}
return euler[l];
}
#undef int
void find_pair(int n, vector<int> U, vector<int> V, int A, int B)
{
#define int ll
N = n;
M = sz(U);
f.resize(N);
for(int i = 0;i < sz(U);i++)
{
vec[U[i]].pb(mp(V[i],i));
vec[V[i]].pb(mp(U[i],i));
}
askvec.resize(M);
for(int i = 0;i < M;i++) askvec[i] = 0;
dist = ask(askvec);
int l = 0;
int r = N - 1;
while(l < r)
{
int mid = (l + r >> 1);
for(int i = 0;i < M;i++) askvec[i] = 0;
for(int i = 0;i <= mid;i++)
{
for(auto it : vec[i])
{
askvec[it.second] = 1;
}
}
if(ask(askvec) != dist) r = mid;
else l = mid + 1;
}
root(l);
int X = bs();
root(X);
int Y = bs();
answer(X,Y);
}
/*
int32_t main(){_
//freopen("input","r",stdin);
return 0;
}*/
컴파일 시 표준 에러 (stderr) 메시지
highway.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
# pragma GCC optimization ("unroll-loops")
highway.cpp: In function 'long long int bs()':
highway.cpp:102:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r + 1 >> 1;
~~~~~~^~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:135:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = (l + r >> 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... |