#include "highway.h"
#include<vector>
#include<queue>
#include<bitset>
using namespace std;
#define MAXN 90005
typedef long long lint;
typedef pair<int, int> pii;
int N, M;
lint d;
int se;
vector<pii> ed[MAXN];
int da[MAXN], db[MAXN];
bitset<MAXN> chk;
int num[MAXN];
void bfs(int x, int dx[]) {
queue<int> q;
for(int i = 0; i < N; i++) dx[i] = -1;
dx[x] = 0;
q.push(x);
while(!q.empty()) {
int t = q.front();
q.pop();
for(auto a : ed[t]) if(dx[a.first] == -1) {
dx[a.first] = dx[t] + 1;
q.push(a.first);
}
}
}
int f(int x, int dx[], int dy[]) {
queue<int> q;
vector<int> con;
for(int i = 0; i < N; i++) chk[i] = false;
q.push(x);
chk[x] = true;
while(!q.empty()) {
int t = q.front();
q.pop();
con.push_back(t);
for(auto a : ed[t]) if(dx[a.first] < dy[a.first] && !chk[a.first]) {
chk[a.first] = true;
q.push(a.first);
}
}
for(int i = 0; i < N; i++) num[i] = -1;
for(int i = 0; i < con.size(); i++) num[con[i]] = i;
/*
for(auto a : con) printf("%d ", a);
printf("\n");
*/
vector<int> w(M, 0);
int s = 0, e = con.size() - 1;
int m = (s + e) / 2;
for(int i = m + 1; i <= e; i++) for(auto a : ed[con[i]]) w[a.second] = 1;
while(s < e) {
//printf("s = %d, e = %d\n", s, e);
if(ask(w) == d) {
e = m;
m = (s + e) / 2;
for(int i = m + 1; i <= e; i++) for(auto a : ed[con[i]]) w[a.second] = 1;
}
else {
s = m + 1;
m = (s + e) / 2;
for(int i = s + 1; i <= m; i++) for(auto a : ed[con[i]]) if(num[a.first] < i) w[a.second] = 0;
}
}
return con[s];
}
void find_pair(int n, vector<int> U, vector<int> V, int A, int B) {
N = n;
M = U.size();
vector<int> w(M, 0);
for(int i = 0; i < M; i++) {
ed[U[i]].push_back(make_pair(V[i], i));
ed[V[i]].push_back(make_pair(U[i], i));
}
d = ask(w);
int s = 0, e = M - 1, m = (M-1) / 2;
for(int i = m + 1; i <= e; i++) w[i] = 1;
while(s < e) {
if(ask(w) != d) {
s = m + 1;
m = (s + e) / 2;
for(int i = s; i <= m; i++) w[i] = 0;
}
else {
e = m;
m = (s + e) / 2;
for(int i = m + 1; i <= e; i++) w[i] = 1;
}
}
se = s;
int alpha = U[se], beta = V[se];
//printf("se=%d(%d, %d)\n", se, alpha, beta);
bfs(alpha, da);
bfs(beta, db);
//for(int i = 0; i < N; i++) printf("[%d %d]\n", da[i], db[i]);
answer(f(alpha, da, db), f(beta, db, da));
}
Compilation message
highway.cpp: In function 'int f(int, int*, int*)':
highway.cpp:55:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < con.size(); i++) num[con[i]] = i;
~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2424 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
2484 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
3132 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
2552 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
3232 KB |
Output is correct |
2 |
Incorrect |
25 ms |
3272 KB |
Output is incorrect: {s, t} is wrong. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
51 ms |
3240 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |