-2

This is my code.

#include<bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define pb push_back;
#define rep(i,j,k) for(int i = j;i < k; i++)

vector<int> r;
bool bad[10006];

bool track(int y){
    if(bad[y]) return 1;
    rep(i,0,(int)r[y].size()){
        if(track(r[y][i])) return 1;
    }
    return 0;
}

int main(){
    IOS
    int n,m,l,q;
    cin >> n >> m >> l >> q;
    rep(i,0,m){
        int a,b; cin >> a >> b;
        r[b].pb(a);
    }
    rep(i,0,l){
        int x; cin >> x;
        bad[x] = 1;
    }
    rep(i,0,q){
        int y; cin >> y;
        if(track(y)){
            cout << "TUIHUOOOOOO\n";
        }
        else{
            cout << "YA~~\n";
        }
    }
    return 0;
}

Dev c++ kept saying that rep(i,0,(int)r[y].size()) has invalid type int[int]. I don't understand why this is invalid. I have searched for this problem but don't get any answer. The problem I only think of is that I used the same name to announce different data type, but I think I don't make this mistake.

1 Answers1

1

In r[y].size(), r is a vector<int>, so r[y] is an int. There is no method called size that can be called on an int (or in fact any method at all). That's explains the error.

Your code is treating r as if it is a two dimensional vector/array, but it isn't. So vector<vector<int>> r; would help, but your code has other problems as you'll find out when you run it.

And please stop using those macros. Apart from being badly written, they also obscure your code. If you were in my class and you handed that it, I would fail you. I really hope you haven't been told that you must use them.

john
  • 85,011
  • 4
  • 57
  • 81