이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using i64 = long long;
const int MAXN = 2e5 + 5;
const int BLOCK_SIZE = 470;
#define ALL(a) (a).begin(), (a).end()
int N, M, Q;
vector<int> adj[MAXN];
vector<int> radj[MAXN];
bool is_deleted[MAXN];
vector<pii> dp[MAXN];
int dist[MAXN];
bool vis[MAXN];
vector<pii> merge_vector(const vector<pii> &a, const vector<pii> &b) {
vector<pii> res;
vector<pii> ans;
for(auto [x, y] : a)
res.emplace_back(x, y);
for(auto [x, y] : b)
res.emplace_back(x + 1, y);
sort(ALL(res));
reverse(ALL(res));
for(auto [x, y] : res) {
if(vis[y] == false)
ans.emplace_back(x, y);
vis[y] = true;
}
for(auto [x, y] : res) vis[y] = false;
return ans;
}
signed main() {
#define TASK "code"
if (fopen(TASK ".inp", "r")) {
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> M >> Q;
for(int i = 1; i <= M; i++) {
int u, v;
cin >> u >> v;
adj[u].emplace_back(v);
radj[v].emplace_back(u);
}
for(int u = 1; u <= N; u++) {
dp[u].emplace_back(0, u);
for(int v : radj[u])
dp[u] = merge_vector(dp[u], dp[v]);
}
while(Q--) {
int u;
cin >> u;
int sz;
cin >> sz;
vector<int> a(sz, 0);
for(int &x : a) cin >> x;
for(int x : a) is_deleted[x] = true;
if(a.size() >= BLOCK_SIZE) {
int ans = -1;
for(int i = 1; i <= N; i++) dist[i] = -1;
dist[1] = 0;
for(int i = 2; i <= N; i++) {
for(int v : radj[i])
dist[i] = max(dist[i], dist[v] + 1);
}
cout << dist[u] << "\n";
} else {
int ans = -1;
for(auto [x, y] : dp[u]) {
if(is_deleted[y] == false) ans = max(ans, x);
}
cout << ans << "\n";
}
for(int x : a) is_deleted[x] = false;
}
return (0 ^ 0);
}
컴파일 시 표준 에러 (stderr) 메시지
bitaro.cpp: In function 'int main()':
bitaro.cpp:68:17: warning: unused variable 'ans' [-Wunused-variable]
68 | int ans = -1;
| ^~~
bitaro.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | freopen(TASK ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | freopen(TASK ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |