# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
49575 | daniel_02 | Bitaro’s Party (JOI18_bitaro) | C++17 | 2045 ms | 8004 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>
#define pb push_back
#define fr first
#define sc second
using namespace std;
const int N = 1e5 + 7;
const int inf = 1e9 + 7;
priority_queue<pair<int, int>>q;
vector<pair<int, int>>g[N];
bool busy[N];
int d[N];
main()
{
int n, m, Q;
cin >> n >> m >> Q;
for (int i = 1; i <= m; i ++)
{
int u, v;
scanf("%d%d", &u, &v);
g[v].pb({u, 1});
}
while (Q--)
{
int t, k, mx;
scanf("%d%d", &t, &k);
for (int i = 0; i < k; i++)
{
int a;
scanf("%d", &a);
busy[a] = 1;
}
for (int i = 1; i <= n; i++)
d[i] = -inf;
q.push({t, 0});
d[t] = 0;
while (!q.empty())
{
int v = q.top().fr, cs = q.top().sc * -1;
q.pop();
if (d[v] < cs)continue;
for (int i = 0; i < g[v].size(); i++)
{
int to = g[v][i].fr, cost = g[v][i].sc;
if (d[to] < cost + d[v])
{
// cout << v << " " << to << " " << d[v] << endl;
d[to] = cost + d[v];
q.push({to, -d[v]});
}
}
}
mx = -1;
for (int i = 1; i <= n; i++)
{
if (!busy[i] && d[i] != -inf)
{
mx = max(mx, d[i]);
}
}
if (mx == -1 || mx == -inf)
{
cout << -1 << endl;
continue;
}
cout << mx << endl;
memset(busy, 0, sizeof(busy));
}
}
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... |