이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i <= b; ++i)
const int maxn=1e5+7,CUT=100;
vector<int> adj[maxn],bck[maxn];
int n, m, q, sz, st, BUSYI[maxn], busy[maxn], dp[maxn];
int slow(int s)
{
rep (i, 1, n)
dp[i] = -1e9;
dp[s] = 0;
for (int i = s - 1; i >= 1; --i)
{
for (auto k : adj[i])
dp[i] = max (dp[i], dp[k] + 1);
}
int mx = -1;
rep (i, 1, s)
if (!busy[i])
mx = max (mx, dp[i]);
return mx;
}
vector< pair<int,int> > best[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> q;
for(int i=1;i<=m;i++)
{
int u,v;
cin >> u >> v;
adj[u].push_back(v);
bck[v].push_back(u);
}
vector< pair<int,int> > help={};
rep (i,1 ,n)
{
help={};
for(auto node_back:bck[i])
for(auto k:best[node_back])
help.push_back({k.first+1,k.second});
help.push_back({0,i});
sort(help.begin(),help.end());
reverse(help.begin(),help.end());
for(auto k:help)
{
if(busy[k.second]==0)
{
busy[k.second]=1;
best[i].push_back(k);
if(best[i].size()==CUT)break;
}
}
for(auto k:best[i])
busy[k.second]=0;
}
for(int i=1;i<=q;i++)
{
cin >> st >> sz;
for(int j=1;j<=sz;j++)
{
cin >> BUSYI[j];
busy[BUSYI[j]]=1;
}
if(sz>=CUT)cout << slow(st) << '\n';
else
{
int mx=-1;
for(auto k:best[st])
if(busy[k.second]==0)mx=max(mx,k.first);
cout << mx << '\n';
}
for(int j=1;j<=sz;j++)
busy[BUSYI[j]]=0;
}
return 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... |