Submission #567142

#TimeUsernameProblemLanguageResultExecution timeMemory
5671421zaid1Bitaro’s Party (JOI18_bitaro)C++14
0 / 100
2094 ms468 KiB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef long long ll;
const int M = 3e3 + 5, MOD = 1e9+7;
vector<int> node[M], inv[M], top;
map<int, int> is;
int vis[M], ans;

void dfs(int s, int d = 0) {
    if (!is[s]) ans = max(ans, d);
    for (int i:inv[s]) {
        dfs(i, d+1);
    }
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    srand(time(0));
    
    int n, m, t;
    cin >> n >> m >> t;

    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        node[a].push_back(b);
        inv[b].push_back(a);
    }

    while (t--) {
        int s, k;
        cin >> s >> k;

        for (int i = 1; i <= k; i++) {
            int a;
            cin >> a;

            is[a] = true;
        }

        ans = -1;
        dfs(s);
        cout << ans << endl;
        is.clear();
    }

    return 0;
}
 
/*
5 6 3
1 2
2 4
3 4
1 3
3 5
4 5
4 1 1
5 2 2 3
2 3 1 4 5

12 17 10 
1 2
2 3
3 4
1 5
2 6
3 7
4 8
5 6
6 7
7 8
5 9
6 10
7 11
8 12
9 10
10 11
11 12
6 3 1 7 12
3 7 1 2 3 4 5 6 7
11 3 1 3 5
9 2 1 9
8 4 1 2 3 4
1 1 1
12 0
10 3 1 6 10
11 8 2 3 5 6 7 9 10 11
8 7 2 3 4 5 6 7 8
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...