/ SeriousOJ /

Record Detail

Compile Error

foo.cc:7:12: error: 'std::vector<int> index' redeclared as different kind of entity
    7 | vector<int>index;
      |            ^~~~~
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/13/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:121,
                 from foo.cc:1:
/usr/include/strings.h:61:1: note: previous declaration 'const char* index(const char*, int)'
   61 | index (const char *__s, int __c) __THROW
      | ^~~~~
foo.cc: In function 'void dfs(int, int)':
foo.cc:26:11: error: overloaded function with no contextual type information
   26 |     index.push_back(x);
      |           ^~~~~~~~~
foo.cc: In function 'int main()':
foo.cc:62:20: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   62 |         int x=index[i];
      |                    ^
foo.cc:69:13: error: overloaded function with no contextual type information
   69 |       index.clear();
      |             ^~~~~

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=2e5+10,MOD=1000000007;
typedef long long ll;
vector<int>edge[M];
int in[M],out[M];
vector<int>index;
int bit[M];
int cnt=1;
int query(int id){
    int sum=0;
    while(id>0){
         sum+=bit[id];
         id-=id&(-id);
    }
    return sum;
}
void upade(int id,int val,int n){
           while(id<=n){
            bit[id]+=val;
            id+=id&(-id);
           }
}
void dfs(int x,int p){
    in[x]=cnt;
    index.push_back(x);
    for(int u:edge[x]){
        if(u!=p){
            dfs(u,x);
        }
    }
    cnt++;
    out[x]=cnt;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    int cas=1;
    while(t--){
     
      int n,q;
      cin>>n>>q;
      vector<int>a(n+1);
      for(int i=1;i<=n;i++)cin>>a[i];
      for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        edge[x].push_back(y);
        edge[y].push_back(x);
      }
      cnt=1;
      dfs(1,-1);
      while(q--){
        int node;
        cin>>node;
        upade(in[node],1,n);
      }
      for(int i=0;i<n;i++){
        int x=index[i];
        int cnt=query(in[x])-query(in[x]-1);
        if(cnt&1){
            if(a[x]==0)a[x]=1;
            else a[x]=0;
        }
      }
      index.clear();
    //  cas++;
      cout<<"Case "<<cas<<": ";
      for(int i=1;i<=n;i++)cout<<a[i]<<" ";
        cout<<"\n";
     for(int i=1;i<=n;i++){
        edge[i].clear();
        in[i]=0;
        out[i]=0;
        bit[i]=0;
     }
     cas++;

   }
       

    
    return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1003 Tahsin and Tree
Contest
Beta Round #1
Language
C++17 (G++ 13.2.0)
Submit At
2023-11-29 17:37:25
Judged At
2024-11-11 03:50:36
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes