이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define REV(i, b, a) for(int i = (b); i >= (a); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define ll long long
#define fi first
#define se second
#define int long long
using namespace std;
const int N = 1e5 + 5;
int n, m, q;
vector<int> rg[N];
int block;
bool blocked[N];
vector<pair<int, int>> pre[N];
int dp[N];
int from[N];
void solve(int tc) {
cin >> n >> m >> q;
block = sqrt(n) + 1;
REP(_, m) {
int u, v;
cin >> u >> v;
--u; --v;
rg[v].emplace_back(u);
}
memset(from, -1, sizeof from);
REP(i, n) {
pre[i].emplace_back(0, i);
vector<int> from_i;
for(int _ = 0; _ < rg[i].size(); ++_) {
int j = rg[i][_];
for(int __ = 0; __ < pre[j].size(); ++__) {
int dist = pre[j][__].fi, idx = pre[j][__].se;
if(from[idx] == -1) {
from_i.emplace_back(idx);
from[idx] = dist + 1;
} else {
from[idx] = max(from[idx], dist + 1);
}
}
}
for(int _ = 0; _ < from_i.size(); ++_) {
int j = from_i[_];
pre[i].emplace_back(from[j], j);
}
sort(pre[i].begin(), pre[i].end(), greater<pair<int, int>>());
while(pre[i].size() > block) pre[i].pop_back();
for(int _ = 0; _ < from_i.size(); ++_) {
int j = from_i[_];
from[j] = -1;
}
}
// FOR(i, 3, 3) {
// for(int j = 0; j < (int)pre[i].size(); ++j) {
// cout << pre[i][j].fi << ' ' << pre[i][j].se << " | ";
// }
// cout << '\n';
// }
REP(_, q) {
int t, y;
cin >> t >> y;
--t;
vector<int> ve(y);
REP(i, y) {
cin >> ve[i];
--ve[i];
blocked[ve[i]] = true;
}
int ans = -1;
if(y > block) {
for(int i = 0; i <= t; ++i) dp[i] = -1;
dp[t] = 0;
for(int i = t; i >= 0; --i) {
if(dp[i] == -1) continue;
if(!blocked[i]) ans = max(ans, dp[i]);
for(int _ = 0; _ < rg[i].size(); ++_) {
int j = rg[i][_];
dp[j] = max(dp[j], dp[i] + 1);
}
}
} else {
for(int i = 0; i < (int)pre[t].size(); ++i) {
if(!blocked[pre[t][i].se]) {
ans = pre[t][i].fi;
break;
}
}
}
cout << ans << '\n';
for(int i = 0; i < (int)ve.size(); ++i) {
blocked[ve[i]] = false;
}
}
return;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int tc = 1;
// cin >> tc;
for(int i = 1; i <= tc; ++i) solve(tc);
return (0);
}
컴파일 시 표준 에러 (stderr) 메시지
bitaro.cpp: In function 'void solve(long long int)':
bitaro.cpp:34:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int _ = 0; _ < rg[i].size(); ++_) {
| ~~^~~~~~~~~~~~~~
bitaro.cpp:36:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int __ = 0; __ < pre[j].size(); ++__) {
| ~~~^~~~~~~~~~~~~~~
bitaro.cpp:46:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int _ = 0; _ < from_i.size(); ++_) {
| ~~^~~~~~~~~~~~~~~
bitaro.cpp:51:29: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
51 | while(pre[i].size() > block) pre[i].pop_back();
| ~~~~~~~~~~~~~~^~~~~~~
bitaro.cpp:52:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int _ = 0; _ < from_i.size(); ++_) {
| ~~^~~~~~~~~~~~~~~
bitaro.cpp:80:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(int _ = 0; _ < rg[i].size(); ++_) {
| ~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |