이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
//#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=1e5+100,sq=300;
pii mx[N][sq];
vector <int> g[N];
ll vis[N];
ll dp[N];
int32_t main(){
sync;
ll n,m,q;
cin >> n >> m >> q;
for (int i=0;i<m;i++){
ll u,v;
cin >> v >> u;
g[u].pb(v);
}
for (int i=1;i<=n;i++){
for (int j=0;j<sq;j++){
mx[i][j]={-1,-1};
}
}
for (int i=1;i<=n;i++){
vector <int> cnt;
for (int j=0;j<g[i].size();j++){
cnt.pb(0);
}
if (cnt.size()==0) continue;
for (int j=0;j<sq;j++){
pii p={0,i};
ll id=0;
for (int k=0;k<g[i].size();k++){
ll u=g[i][k];
ll z=cnt[k];
if (z<sq && mx[u][z].F>=p.F) p=mx[u][z],id=k,p.F++;
}
// cout << p.F << " rfh " << p.S << endl;
cnt[id]++;
mx[i][j]=p;
}
}
// cout << 1 << endl;
//return 0;
ll cnt=1;
while(q--){
cnt++;
ll w,t;
cin >> w >> t;
for (int i=0;i<t;i++){
ll x;
cin >> x;
vis[x]=cnt;
}
ll ans=-1;
for (int i=0;i<sq;i++){
if (vis[mx[w][i].S]!=cnt){
ans=mx[w][i].F;
break;
}
}
if (ans>-1){
//cout << ans << endl;
//continue;
}
memset(dp,0,sizeof dp);
for (int i=1;i<=n;i++){
if (vis[i]==cnt) dp[i]=-1;
for (auto u : g[i]){
if (dp[u]==-1) continue;
dp[i]=max(dp[i],dp[u]+1);
}
}
cout << dp[w] << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
bitaro.cpp: In function 'int32_t main()':
bitaro.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int j=0;j<g[i].size();j++){
| ~^~~~~~~~~~~~
bitaro.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int k=0;k<g[i].size();k++){
| ~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |