Submission #1237561

#TimeUsernameProblemLanguageResultExecution timeMemory
1237561thuhienneBitaro’s Party (JOI18_bitaro)C++20
14 / 100
2094 ms12872 KiB
#include <bits/stdc++.h> using namespace std; #define FastIO ios_base::sync_with_stdio(0);cin.tie(nullptr); #define MULTEST int t;cin >> t;while (t--) solve(); #define rf(__abc__) freopen(__abc__".inp","r",stdin);freopen(__abc__".out","w",stdout); const int mod = 1e9 + 7; long long pw(long long x,long long y) { if (y == 0) return 1; if (y % 2 == 0) { long long a = pw(x,y/2); return a*a%mod; } else { long long a = pw(x,y - 1); return a*x%mod; } } int add(int x,int y) { x += y; if (x >= mod) x -= mod; return x; } int subtract(int x,int y) { x -= y; if (x < 0) x += mod; return x; } int mul(long long x,int y) { x *= y; if (x >= mod) x %= mod; return x; } ///Code goes here int n,m,q; vector <int> adj[200009]; bool busy[100009],visited[100009]; int dp[100009]; int dfs(int node) { if (visited[node]) return dp[node]; visited[node] = 1; dp[node] = (busy[node] ? -1e9 : 0); for (auto x : adj[node]) { dp[node] = max(dp[node],dfs(x) + 1); } return dp[node]; } int main() { //rf(""); FastIO //MULTEST cin >> n >> m >> q; for (int i = 1;i <= m;i++) { int u,v;cin >> u >> v; adj[v].push_back(u); } while (q--) { int root,num;cin >> root >> num; vector <int> record(num + 1); for (int i = 1;i <= num;i++) { cin >> record[i]; busy[record[i]] = 1; } for (int i = 1;i <= n;i++) visited[i] = dp[i] = 0; int d = dfs(root); cout << (d < 0 ? -1 : d) << '\n'; for (int i = 1;i <= num;i++) busy[record[i]] = 0; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...