이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <iterator>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define X first
#define Y second
constexpr int SQ = 80;
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>> adj(n);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--; v--;
adj[v].push_back(u);
}
vector<vector<pii>> best(n);
vector<int> mark(n);
int timer = 1;
for (int i = 0; i < n; i++) {
vector<pii> now = {{0, i}};
for (int j : adj[i]) {
for (pii p : best[j]) {
p.X++;
now.push_back(p);
}
}
sort(begin(now), end(now), greater<>());
for (int j = 0; best[i].size() <= SQ && j < now.size(); j++) {
if (mark[now[j].Y] == timer)
continue;
mark[now[j].Y] = timer;
best[i].push_back(now[j]);
}
timer++;
}
while (q --> 0) {
int t, cnt;
cin >> t >> cnt;
t--;
for (int i = 0; i < cnt; i++) {
int u; cin >> u; u--;
mark[u] = timer;
}
if (cnt > SQ) {
vector<int> dp(n, -1);
for (int i = 0; i < n; i++) {
if (mark[i] != timer)
dp[i] = 0;
for (int j : adj[i]) if (dp[j] > -1) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
cout << dp[t] << '\n';
} else {
int ans = -1;
for (pii const& p : best[t]) {
if (mark[p.Y] != timer) {
ans = p.X;
break;
}
}
cout << ans << '\n';
}
timer++;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bitaro.cpp: In function 'int main()':
bitaro.cpp:37:51: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int j = 0; best[i].size() <= SQ && j < now.size(); j++) {
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |