이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int, int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define mod 1000000007
ofstream fout(".out");
ifstream fin(".in");
vector<int> par[100001];
vector<pair<int, int>> v[100001];
int dis[100001][320], city[100001][320], diss[100001];
ll dd[100001], idk[100001];
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, m, q;
cin >> n >> m >> q;
for(int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
par[v].push_back(u);
}
int sqr = sqrt(n);
for(ll i = 1; i <= n; i++) {
v[i].push_back({0, i});
set<int> s;
for(int j : par[i]) {
int sz = v[j].size();
for(int k = 0; k < sz; k++) {
int d = v[j][k].first, c = v[j][k].second;
s.insert(c);
idk[c] = max(idk[c], i * n + d);
}
}
int sz = s.size() - 1;
for(int i : s) {
int d = idk[i], c = i;
dis[i][sz] = d;
city[i][sz] = c;
sz--;
v[i].push_back({d, c});
if(sz < 0)
break;
}
sort(v[i].rbegin(), v[i].rend());
}
int o = -1e9;
while(q--) {
int t, sz;
cin >> t >> sz;
for(int i = 0; i < sz; i++) {
int x;
cin >> x;
diss[x] = o;
}
if(t > sqr) {
for(int i = 1; i <= t; i++) {
if(diss[i] != o)
diss[i] = 0;
for(int j : par[i])
diss[i] = max(diss[i], diss[j] + 1);
}
if(diss[t] < 0)
diss[t] = -1;
cout << diss[t] << "\n";
o += n + 1;
continue;
}
int ans = -1;
for(int i = 0; i <= sqr; i++) {
if(!city[t][i])
break;
if(diss[city[t][i]] != o) {
ans = dis[t][i];
break;
}
}
o += n + 1;
cout << ans << "\n";
}
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... |