이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef pair<pii, int> piii;
typedef pair<ll, pll> lpll;
typedef pair<pll, ll> plll;
typedef pair<pii, pii> piipii;
typedef pair<pll, pll> pllpll;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define ios ios_base::sync_with_stdio(false), cin.tie(0)
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
const int N = 2e5+25, SQ=130, lg=18;
ll Mod = 1e9+7;
//ll Mod = 998244353;
ll MOD(ll a, ll mod=Mod) {return (a>=0&&a<mod ? a : ((a%mod+mod)%mod));}
ll max(ll a, ll b) {return (a>b ? a : b);}
ll min(ll a, ll b) {return (a<b ? a : b);}
ll abso(ll a) {return (a<0?-a:a);}
inline ll poww(ll a, ll b) {
ll ans = 1;
a=MOD(a);
while (b) {
if (b & 1) ans = MOD(ans*a);
b >>= 1;
a = MOD(a*a);
}
return ans;
}
int n, m, qu, deg[N], mark[N], mark2[N], dist[N];
vector<pii> vec[N];
vector<int> adj[N], rev[N];
void init() {
for(int i=1; i<=n; i++) {
int v = i;
priority_queue<pii, vector<pii>, greater<pii>> pq;
for(auto u : rev[v]) {
for(int i=size(vec[u])-1; i>=0; i--) {
//if(size(pq)==SQ && pq.top().F>=vec[u][i].F+1) break;
pq.push({vec[u][i].F+1, vec[u][i].S});
if(size(pq) > SQ) pq.pop();
}
}
if(size(pq) < SQ) pq.push({0, v});
while(size(pq)) {
vec[v].pb(pq.top());
pq.pop();
}
}
}
void KIAREZ(int v) {
fill(dist, dist+n+2, 0);
for(int i=1; i<=n; i++) {
int u = i;
for(auto w : adj[u]) {
if(mark[u]==0 || dist[u]>0) dist[w] = max(dist[u] + 1, dist[w]);
}
}
if(dist[v]==0 && mark[v]==1) cout<<-1<<endl;
else cout<<dist[v]<<endl;
}
void kiarez(int v) {
int ans = -1;
for(int i=size(vec[v])-1; i>=0; i--) {
if(mark[vec[v][i].S] == 0) {ans = vec[v][i].F; break;}
}
cout<<ans<<endl;
}
int main () {
ios;
cin>>n>>m>>qu;
for(int v,u,i=1; i<=m; i++) {
cin>>v>>u;
adj[v].pb(u);
rev[u].pb(v);
}
init();
while(qu--) {
int t,y;
cin>>t>>y;
vector<int> c;
for(int v,i=1; i<=y; i++) {
cin>>v;
c.pb(v);
mark[v] = 1;
}
if(y >= SQ) {
KIAREZ(t);
} else {
kiarez(t);
}
for(auto it : c) mark[it] = 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... |