Submission #567262

#TimeUsernameProblemLanguageResultExecution timeMemory
567262UzoufBitaro’s Party (JOI18_bitaro)C++14
7 / 100
117 ms2860 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define int long long #define endl "\n" int mod=1e9+7; const int N=1005;//1e5+5; template<class x> using ordered_multiset = tree<x, null_type,less_equal<x>, rb_tree_tag,tree_order_statistics_node_update>; int n,m,t; vector<vector<int> > v(N); int ans[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen(".in", "r", stdin); freopen(".out", "w", stdout); cin>>n>>m>>t; for (int i=0;i<m;i++) { int a,b; cin>>a>>b; v[a].push_back(b); } for (int tt=0;tt<t;tt++) { bool busy[N]; memset(busy,false,sizeof busy); int plc; cin>>plc; int b; cin>>b; for (int i=0;i<b;i++) { int x; cin>>x; busy[x]=true; } priority_queue<pair<int,int> > q; int dis[N]; for (int i=0;i<N;i++) dis[i]=-1e10; for (int i=1;i<=n;i++) { if (busy[i]) continue; q.push({0,i}); dis[i]=0; } while (!q.empty()) { int i=q.top().second; int cst=q.top().first; q.pop(); if (dis[i]>cst) continue; for (int j:v[i]) { int nw=cst+1; if (dis[j]<nw) { dis[j]=nw; q.push({dis[j],j}); } } } if (dis[plc]==-1e10) dis[plc]=-1; ans[tt]=dis[plc]; } for (int i=0;i<t;i++) cout<<ans[i]<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...