| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1349228 | boropoto | Bitaro’s Party (JOI18_bitaro) | C++20 | 1 ms | 344 KiB |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
int dp[MAXN + 5];
vector<int>graph[MAXN + 5];
bool used[MAXN + 5], is[MAXN + 5];
void bfs(int node)
{
queue<int>q;
q.push(node);
dp[node] = 0;
while(!q.empty())
{
int u = q.front(); q.pop();
for(int v : graph[u])
{
if(is[v])continue;
if(dp[v] < dp[u] + 1)
{
dp[v] = dp[u] + 1;
q.push(v);
}
}
}
}
signed main()
{
int n, m, q; cin >> n >> m >> q;
for(int i = 1; i <= m; i++)
{
int x, y; cin >> x >> y;
graph[y].push_back(x);
}
while(q--)
{
int t, s; cin >> t >> s;
for(int i = 1; i <= s; i++)
{
int x; cin >> x;
is[x] = true;
}
if(is[t])
{
cout << -1 << endl;
continue;
}
bfs(t);
int ans = 0;
for(int i = 1; i <= n; i++)
{
if(!is[i])
{
ans = max(ans, dp[i]);
}
}
cout << ans << endl;
}
}| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
