Submission #706669

#TimeUsernameProblemLanguageResultExecution timeMemory
706669keta_tsimakuridzeBitaro’s Party (JOI18_bitaro)C++14
7 / 100
1073 ms410380 KiB
#include<bits/stdc++.h>
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, B = 505, mod = 1e9 + 7; // !
int t, f[N];
struct di {
    pair<int,int> d[B + 5];
} X[N];
vector<int> V[N];
void CALC(int n) {
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= B; j++) {
            X[i].d[j] = {-N, 0};
        }
        X[i].d[0] = {0, i};
        for(int j = 0; j < V[i].size(); j++) {
            di a = X[i], b = X[V[i][j]];
            int x = 0, y = 0;
            for(int k = 0; k <= B; k++) {
                while(x <= B && a.d[x].s && f[a.d[x].s]) ++x;
                while(y <= B && b.d[y].s && f[b.d[y].s]) ++y;
                if(a.d[x].f > b.d[y].f + 1) X[i].d[k] = a.d[x], f[a.d[x].s] = 1, ++x;
                else X[i].d[k] = {b.d[y].f + 1, b.d[y].s}, f[b.d[y].s] = 1, ++y;
            }
            for(int k = 0; k <= B; k++) f[X[i].d[k].s] = 0;
        }
    }
}
main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie();
    int n, m, q;
    cin >> n >> m >> q;
    while(m--) {
        int u, v; cin >> u >> v;
        V[v].push_back(u);
    }

    CALC(n);

    while(q--) {
        int c, y;
        cin >> c >> y;
        if(y > B) {
            vector<int> d(n + 2);
            for(int j = 1; j <= n; j++) d[j] = -N;
            while(y--) {
                int x; cin >> x;
                d[x] = 0;
            }
            for(int i = 1; i <= n; i++) {
                for(int j = 0; j < V[i].size(); j++) {
                    d[i] = max(d[i], d[V[i][j]] + 1);
                }
            }

            cout << max(-1, d[c]) << "\n";
            continue;
        }
        vector<int> v;
        while(y--) {
            int x; cin >> x;
            f[x] = 1;
            v.push_back(x);
        }
        for(int j = 0; j <= B; j++) {
            if(!f[X[c].d[j].s]) {
                cout << max(-1, X[c].d[j].f) << "\n";
                break;
            }
        }
        for(int j = 0; j < v.size(); j++) f[v[j]] = 0;
    }
 }

Compilation message (stderr)

bitaro.cpp: In function 'void CALC(int)':
bitaro.cpp:18:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         for(int j = 0; j < V[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~
bitaro.cpp: At global scope:
bitaro.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main(){
      | ^~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:53:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |                 for(int j = 0; j < V[i].size(); j++) {
      |                                ~~^~~~~~~~~~~~~
bitaro.cpp:73:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for(int j = 0; j < v.size(); j++) f[v[j]] = 0;
      |                        ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...