# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
957963 |
2024-04-04T15:00:54 Z |
Soumya1 |
Park (JOI17_park) |
C++17 |
|
236 ms |
860 KB |
#include "park.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1405;
vector<int> ad[mxN], edges[mxN];
int added[mxN];
int ask[mxN];
int n;
vector<int> all;
bool bad[mxN];
void get(int u) {
all.push_back(u);
for (int v : ad[u]) {
if (bad[v]) continue;
get(v);
}
}
int find_first(vector<int> nodes, int u) {
for (int i = 0; i < n; i++) ask[i] = 0;
for (int i : nodes) ask[i] = 1;
ask[u] = 1;
if (!Ask(nodes[0], u, ask)) return -1;
int lo = 0, hi = nodes.size() - 1;
while (lo < hi) {
int mid = (lo + hi) >> 1;
for (int i = 0; i < n; i++) ask[i] = 0;
for (int i = 0; i <= mid; i++) ask[nodes[i]] = 1;
ask[u] = 1;
if (Ask(nodes[0], u, ask)) hi = mid;
else lo = mid + 1;
}
return nodes[lo];
}
void dfs(int u) {
for (int i = 0; i < n; i++) ask[i] = added[i];
ask[u] = 1;
while (!Ask(0, u, ask)) {
cout << u << endl;
int lo = 0, hi = n - 1;
while (lo < hi) {
int mid = (lo + hi) >> 1;
for (int i = 0; i < n; i++) {
ask[i] = (added[i] || i <= mid);
}
ask[0] = ask[u] = 1;
if (Ask(0, u, ask)) hi = mid;
else lo = mid + 1;
}
dfs(lo);
for (int i = 0; i < n; i++) ask[i] = added[i];
ask[u] = 1;
}
for (int i = 0; i < n; i++) bad[i] = false;
vector<int> roots;
roots.push_back(0);
int some = -1;
for (int i = 0; i < roots.size(); i++) {
int x = roots[i];
while (true) {
all.clear();
get(x);
int v = find_first(all, u);
if (v == -1) break;
some = v;
bad[v] = true;
edges[v].push_back(u);
for (int childs : ad[v]) roots.push_back(childs);
if (v == x) break;
}
}
ad[some].push_back(u);
added[u] = 1;
}
void Detect(int T, int N) {
n = N;
added[0] = 1;
for (int i = 1; i < N; i++) {
if (!added[i]) {
dfs(i);
}
}
for (int i = 0; i < n; i++) {
for (int j : edges[i]) {
Answer(min(i, j), max(i, j));
}
}
}
Compilation message
park.cpp: In function 'void dfs(int)':
park.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i = 0; i < roots.size(); i++) {
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Program terminated incorrectly, or you printed something to stdout |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
236 ms |
600 KB |
Program terminated incorrectly, or you printed something to stdout |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
604 KB |
Program terminated incorrectly, or you printed something to stdout |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Program terminated incorrectly, or you printed something to stdout |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
860 KB |
Program terminated incorrectly, or you printed something to stdout |
2 |
Halted |
0 ms |
0 KB |
- |