# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
117035 | PeppaPig | Bitaro’s Party (JOI18_bitaro) | C++14 | 2061 ms | 278144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1e5+5;
const int B = 320;
int n, m, q;
int dp[N], chk[N];
vector<int> g[N];
void solve(vector<int> &v) {
fill_n(dp, N, -1e9);
memset(chk, 0, sizeof chk);
for(int i : v) chk[i] = true;
for(int u = 1; u <= n; u++) {
if(!chk[u]) dp[u] = max(dp[u], 0);
for(int v : g[u]) if(dp[v] != -1e9)
dp[u] = max(dp[u], dp[v] + 1);
}
}
vector<pii> pre[N];
int mx[N];
void preprocess() {
fill_n(mx, N, -1);
for(int i = 1; i <= n; i++) {
pre[i] = vector<pii>(B, pii(-1, -1));
pre[i][0] = pii(0, i);
}
for(int u = 1; u <= n; u++) {
vector<int> all(1, u);
mx[u] = 0;
for(int v : g[u]) for(pii p : pre[v]) if(p.x != -1) {
mx[p.y] = max(mx[p.y], p.x + 1);
all.emplace_back(p.y);
}
for(int i : all) {
pre[u].emplace_back(mx[i], i);
mx[i] = -1;
}
sort(pre[u].begin(), pre[u].end(), greater<pii>());
pre[u].resize(B);
}
}
bitset<N> tchk;
int main() {
scanf("%d %d %d", &n, &m, &q);
for(int i = 1, a, b; i <= m; i++) {
scanf("%d %d", &a, &b);
if(a > b) swap(a, b);
g[b].emplace_back(a);
}
preprocess();
for(int i = 1, t, y; i <= q; i++) {
scanf("%d %d", &t, &y);
vector<int> block;
for(int i = 1, a; i <= y; i++) {
scanf("%d", &a);
block.emplace_back(a);
}
if(y >= B) {
solve(block);
if(dp[t] != -1e9) printf("%d\n", dp[t]);
else printf("-1\n");
} else {
bool valid = false;
for(int i : block) tchk[i] = true;
for(int i = 0; i < B; i++) if(pre[t][i] != pii(-1, -1) && !tchk[pre[t][i].y]) {
valid = true;
printf("%d\n", pre[t][i].x);
break;
}
if(!valid) printf("-1\n");
for(int i : block) tchk[i] = false;
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |