이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int sq;
vector<bool> bl;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, q; cin >> n >> m >> q;
bl.resize(n, 0);
sq = sqrt(n+0.0);
vector<vector<int>> v(n);
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b; a--, b--;
v[a].pb(b);
}
vector<vector<pair<int, int>>> dps(n);
for(int i = 0; i < n; i++) dps[i].pb({0, i});
for(int i = 0; i < n; i++){
for(int x: v[i]){
vector<pair<int, int>> c;
int s1 = dps[i].size(), s2 = dps[x].size();
for(int aa = 0, bb = 0; aa < s1 || bb < s2;){
if(aa >= s1){
if(!bl[dps[x][bb].sc]) bl[dps[x][bb].sc] = 1, c.pb(dps[x][bb]);
bb++;
}
else if(bb >= s2){
if(!bl[dps[i][aa].sc]) bl[dps[i][aa].sc] = 1, c.pb({dps[i][aa].f+1, dps[i][aa].sc});
aa++;
}
else if(dps[i][aa].f+1 >= dps[x][bb].f){
if(!bl[dps[i][aa].sc]) bl[dps[i][aa].sc] = 1, c.pb({dps[i][aa].f+1, dps[i][aa].sc});
aa++;
}
else{
if(!bl[dps[x][bb].sc]) bl[dps[x][bb].sc] = 1, c.pb(dps[x][bb]);
bb++;
}
}
for(int i = 0; i < c.size(); i++) bl[c[i].sc] = 0;
dps[x] = c;
}
}
vector<bool> busy(n, 0);
while(q--){
int tj, yj; cin >> tj >> yj;
tj--;
vector<int> cbs(yj);
for(int &x: cbs) cin >> x, x--, busy[x] = 1;
if(yj < sq){
int ans = busy[tj] ? -1 : 0;
for(auto [c, nd]: dps[tj]) if(!busy[nd]) ans = max(ans, c);
cout << ans << "\n";
for(int x: cbs) busy[x] = 0;
continue;
}
vector<int> dp(n, -1);
for(int i = 0; i < n; i++){
if(busy[i] && dp[i] == -1) continue;
dp[i] = max(dp[i], 0);
for(int x: v[i]) dp[x] = max(dp[x], dp[i]+1);
}
cout << dp[tj] << "\n";
for(int x: cbs) busy[x] = 0;
}
}
컴파일 시 표준 에러 (stderr) 메시지
bitaro.cpp: In function 'int main()':
bitaro.cpp:45:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i = 0; i < c.size(); i++) bl[c[i].sc] = 0;
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |