# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
241588 | Mercenary | Bitaro’s Party (JOI18_bitaro) | C++14 | 8 ms | 5248 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define pb push_back
#define mp make_pair
#define taskname "A"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int maxn = 1e5 + 5;
int n , m , q;
vector<int> adj[maxn];
int f[maxn];
bool used[maxn];
bool tmp[maxn];
vector<ii> can[maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r")){
freopen(taskname".INP", "r",stdin);
freopen(taskname".OUT", "w",stdout);
}
cin >> n >> m >> q;
while(m--){
int u , v;cin >> u >> v;adj[v].pb(u);
}
for(int i = 1 ; i <= n ; ++i){
can[i].pb(mp(-1 , i));
for(auto v : adj[i]){
vector<ii> val;
auto add = [&](vector<ii> & val , ii c){
if(val.size() == 300 || tmp[c.second] == 1)return;
val.pb(c);
tmp[c.second] = 1;
};
int j = 0;
for(auto & c : can[i]){
while(j < can[v].size() && can[v][j] >= c)add(val , can[v][j++]);
add(val , c);
}
while(j < can[v].size())add(val , can[v][j++]);
can[i] = val;
for(auto & c : val)tmp[c.second] = 0;
}
for(auto & c : can[i]){
c.first++;
}
}
while(q--){
int u;cin >> u;
int k;cin >> k;vector<int> val(k);
for(auto & c : val){
cin >> c;
tmp[c] = 1;
}
if(k > 280){
for(int i = 1 ; i <= u ; ++i){
f[i] = (tmp[i] == 0 ? 0 : -1e9);
for(auto v : adj[i]){
f[i] = max(f[i] , f[v] + 1);
}
}
cout << f[u] << '\n';
}else{
int res = 0;
for(auto & c : can[u]){
if(tmp[c.second] == 0){
res = c.first;break;
}
}
cout << res << '\n';
}
for(auto & c : val){
tmp[c] = 0;
}
}
}
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... |