이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n,m,u,v,disU[90001],disV[90001],con;
ll Base,a,b;
vector<int> w;
vector<pii> adj[90001],Edge;
bool vis[90001];
void F(int* dis, int start) {
memset(vis,0,sizeof(vis));
for (int i=0; i<n; ++i) dis[i]=1e9;
queue<int> q;
q.push(start);
dis[start]=0;
while (!q.empty()) {
int node=q.front();
q.pop();
if (vis[node]) continue;
vis[node]=true;
for (auto s : adj[node]) {
if (dis[s.first]>dis[node]+1) {
dis[s.first]=dis[node]+1;
q.push(s.first);
}
}
}
}
int f(int* dis1, int* dis2, int start) {
memset(vis,0,sizeof(vis));
queue<int> q;
vector<int> edge;
q.push(start);
vis[start]=true;
while (!q.empty()) {
int node=q.front();
q.pop();
for (auto s : adj[node]) {
if (vis[s.first]) continue;
if (dis1[s.first]>=dis2[s.first]) continue;
vis[s.first]=true;
edge.push_back(s.second);
q.push(s.first);
}
}
vector<int> temp;
for (int i=0; i<m; ++i) temp.push_back(1);
for (auto s : edge) temp[s]=0;
temp[con]=0;
ll base=ask(temp);
int l=-1, r=edge.size()-1;
while (l<r) {
int mid=(l+r+1)/2;
for (int i=0; i<edge.size(); ++i) {
if (i<mid) temp[edge[i]]=0;
else temp[edge[i]]=1;
}
if (ask(temp)==base) r=mid-1;
else l=mid;
}
if (l==-1) return start;
if (dis1[Edge[edge[l]].first]<dis1[Edge[edge[l]].second]) return Edge[edge[l]].second;
else return Edge[edge[l]].first;
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
m=U.size();
n=N; a=A; b=B;
for (int i=0; i<m; ++i) {
w.push_back(0);
adj[U[i]].push_back({V[i],i});
adj[V[i]].push_back({U[i],i});
Edge.push_back({U[i],V[i]});
}
Base=ask(w);
int l=0, r=m-1;
while (l<r) {
int mid=(l+r)/2;
for (int i=0; i<m; ++i) {
if (i<=mid) w[i]=0;
else w[i]=1;
}
if (ask(w)==Base) r=mid;
else l=mid+1;
}
u=U[l];
v=V[l];
con=l;
F(disU,u);
F(disV,v);
answer(f(disU,disV,u),f(disV,disU,v));
}
컴파일 시 표준 에러 (stderr) 메시지
highway.cpp: In function 'int f(int*, int*, int)':
highway.cpp:68:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for (int i=0; i<edge.size(); ++i) {
| ~^~~~~~~~~~~~
# | 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... |