| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 768583 | AdamGS | Bitaro’s Party (JOI18_bitaro) | C++17 | 500 ms | 88984 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e5+7, K=100, INF=1e9+7;
vector<int>V[LIM];
vector<pair<int,int>>P[LIM];
int odw[LIM], kiedy[LIM], czy[LIM], najd[LIM], akt, akt2;
void lacz(int a, int b) {
++akt;
vector<pair<int,int>>tmp;
int la=0, lb=0;
while(tmp.size()<K && (la<P[a].size() || lb<P[b].size())) {
if(lb==P[b].size() || la<P[a].size() && P[a][la].nd>=P[b][lb].nd+1) {
if(kiedy[P[a][la].st]<akt) {
kiedy[P[a][la].st]=akt;
tmp.pb(P[a][la]);
}
++la;
} else {
if(kiedy[P[b][lb].st]<akt) {
kiedy[P[b][lb].st]=akt;
tmp.pb({P[b][lb].st, P[b][lb].nd+1});
}
++lb;
}
}
P[a]=tmp;
}
void DFS(int x) {
odw[x]=1;
P[x].pb({x, 0});
for(auto i : V[x]) {
if(!odw[i]) DFS(i);
lacz(x, i);
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
while(m--) {
int a, b;
cin >> a >> b; --a; --b;
V[b].pb(a);
}
rep(i, n) if(!odw[i]) DFS(i);
while(q--) {
int x, y;
cin >> x >> y; --x;
++akt2;
rep(i, y) {
int a;
cin >> a; --a;
czy[a]=akt2;
}
if(y<K) {
int ans=-1;
for(auto i : P[x]) if(czy[i.st]<akt2) ans=max(ans, i.nd);
cout << ans << '\n';
continue;
}
rep(i, x+1) {
if(czy[i]) najd[i]=-INF;
else najd[i]=0;
for(auto j : V[i]) najd[i]=max(najd[i], najd[j]+1);
}
cout << max(najd[x], -1) << '\n';
}
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
