이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define ll long long
#define ff first
#define ss second
#define int ll
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define pii pair <int, int>
using namespace std;
const int inf = 1e15;
const int mod = 1e9+7;
const int N = 3e5+100;
vector < vector <int> > g(N);
vector <int> bfs(int v){
vector <int> d(N, -1); d[v] = 0;
for (int u = v - 1; u >= 1; --u){
for (auto to : g[u])
if (d[to] != -1) d[u] = max(d[u], d[to] + 1);
}
return d;
}
void solve(){
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i < m; ++i){
int a, b; cin >> a >> b;
g[a].pb(b);
//g[b].pb(a);
}
while (q--){
int t, y;
cin >> t >> y;
set <int> c;
for (int i = 0; i < y; ++i){
int a; cin >> a; c.insert(a);
}
vector <int> d = bfs(t);
int ans = -1;
for (int i = 1; i <= n; ++i)
if (!c.count(i)) ans = max(ans, d[i]);
//for (int i = 1; i <= n; ++i) cout << d[i] << " "; cout << '\n';
cout << ans << '\n';
}
}
signed main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int tt = 1;
//cin >> tt;
while (tt--){
solve();
cout << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |