#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 A, B;
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 >> 1;
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 * A) {
e = m;
m = s + e >> 1;
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 >> 1;
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();
A = (lint)a;
B = (lint)b;
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) / A;
int s = 0, e = M - 1, m = N - 1 >> 1;
for(int i = m + 1; i <= e; i++) w[i] = 1;
while(s < e) {
if(ask(w) != A * d) {
s = m + 1;
m = s + e >> 1;
for(int i = s; i <= m; i++) w[i] = 0;
}
else {
e = m;
m = s + e >> 1;
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:56:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < con.size(); i++) num[con[i]] = i;
~~^~~~~~~~~~~~
highway.cpp:65:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = s + e >> 1;
~~^~~
highway.cpp:71:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
m = s + e >> 1;
~~^~~
highway.cpp:76:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
m = s + e >> 1;
~~^~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:96:30: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
int s = 0, e = M - 1, m = N - 1 >> 1;
~~^~~
highway.cpp:101:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
m = s + e >> 1;
~~^~~
highway.cpp:106:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
m = s + e >> 1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2344 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
2500 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
3132 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
2480 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
3224 KB |
Output is correct |
2 |
Incorrect |
26 ms |
3196 KB |
Output is incorrect: {s, t} is wrong. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
3272 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |