이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <queue>
#include <stack>
#include <algorithm>
#include <string.h>
#include <functional>
#include <numeric>
#define task ""
#define size() size() * 1ll
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define MASK(x) (1LL << (x))
#define BIT(x,i) (((x) >> (i)) & 1)
#define numbit(x) __builtin_popcountll(x)
using namespace std;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef long long ll;
template<class t>
bool mini(t &x,t y) {
if (y < x) {
x = y;
return 1;
}
return 0;
}
template<class t>
bool maxi(t &x,t y) {
if (x < y) {
x = y;
return 1;
}
return 0;
}
const int N = 1e6 + 1;
const int M = 1e3 + 1;
const long long mod = 1e9 + 7;
const long long oo = 1e18 + 7;
int n, m, q, k;
int c[N];
bool vis[N], take[N];
vi a[N], b[N];
vii d[N];
void solve(int test = -1) {
cin >> n >> m >> q;
k = __builtin_sqrt(n) + 1;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
a[x].pb(y);
b[y].pb(x);
}
for (int u = 1; u <= n; u++) {
for (int v: b[u]) {
vii best;
d[v].pb(pii(0, v));
int i = 0, j = 0;
while (best.size() < k && (i < d[v].size() || j < d[u].size())) {
if (j == d[u].size() || (i < d[v].size() && d[v][i].fi + 1 >= d[u][i].fi)) {
d[v][i].fi++;
best.pb(d[v][i]);
vis[d[v][i].se] = 1;
d[v][i].fi--;
i++;
} else {
best.pb(d[u][j]);
vis[d[u][j].se] = 1;
j++;
}
while (i < d[v].size() && vis[d[v][i].se]) i++;
while (j < d[u].size() && vis[d[u][j].se]) j++;
}
d[v].pop_back();
for (pii x: best) vis[x.se] = 0;
swap(d[u], best);
}
}
while (q--) {
int t, y;
cin >> t >> y;
for (int i = 1; i <= y; i++) {
int x;
cin >> x;
c[i] = x;
take[x] = 1;
}
int res = -1;
if (y <= k) {
for (pii x: d[t]) {
if (!take[x.se]) {
res = x.fi;
break;
}
}
if (!take[t]) res = max(res, 0);
} else {
vi best(n + 1, 0);
for (int i = 1; i <= y; i++) best[c[i]] = -1;
for (int i = 1; i <= t; i++) {
if (best[i] == -1) continue;
for (int v: a[i]) {
maxi(best[v], best[i] + 1);
}
}
res = best[t];
if (!take[t]) maxi(res, 0);
}
cout << res << '\n';
for (int i = 1; i <= y; i++) take[c[i]] = 0;
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen(task".inp", "r", stdin);
// freopen(task".out", "w", stdout);
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++) {
solve(i);
}
return 0;
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
bitaro.cpp: In function 'void solve(int)':
bitaro.cpp:66:32: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
66 | while (best.size() < k && (i < d[v].size() || j < d[u].size())) {
| ~~~~~~~~~~~~^~~
bitaro.cpp:66:42: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
66 | while (best.size() < k && (i < d[v].size() || j < d[u].size())) {
| ^
bitaro.cpp:66:61: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
66 | while (best.size() < k && (i < d[v].size() || j < d[u].size())) {
| ^
bitaro.cpp:67:23: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
67 | if (j == d[u].size() || (i < d[v].size() && d[v][i].fi + 1 >= d[u][i].fi)) {
| ^
bitaro.cpp:67:44: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
67 | if (j == d[u].size() || (i < d[v].size() && d[v][i].fi + 1 >= d[u][i].fi)) {
| ^
bitaro.cpp:78:26: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
78 | while (i < d[v].size() && vis[d[v][i].se]) i++;
| ^
bitaro.cpp:79:26: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
79 | while (j < d[u].size() && vis[d[u][j].se]) 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... |