Submission #334672

# Submission time Handle Problem Language Result Execution time Memory
334672 2020-12-09T18:14:00 Z iulia13 Biochips (IZhO12_biochips) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <deque>
#include <vector>
using namespace std;
int dp[505][400005];
vector <int> g[200005];
int v[200005];
int in[200005];
int out[200005];
int ord[200005];
int time = 0;
void dfs(int nod)
{
    in[nod] = ++time;
    ord[time] = nod;
    for (int i = 0; i < g[nod].size(); i++)
    {
        int x = g[nod][i];
        dfs(x);
    }
    out[nod] = ++time;
}
int main()
{
    int n, m, i, j, r, k, l, x;
    cin >> n >> m;
    for (i = 1; i <= n; i++)
    {
        cin >> x >> v[i];
        if (x)
            g[x].push_back(i);
        else
            r = i;
    }
    dfs(r);
    for (j = 0; j <= m; j++)
        for (i = 1; i <= time; i++)
            dp[j][i] = -2e9;
    dp[0][1] = 0;
    for (j = 0; j <= m; j++)
        for (i = 1; i <= time; i++)
        {
            int last = out[ord[i]];
            dp[j][i + 1] = max(dp[j][i + 1], dp[j][i]);
            if (j < m)
                dp[j + 1][last] = max(dp[j + 1][last], dp[j][i] + v[ord[i]]);
        }
    cout << dp[m][time];
    return 0;
}

Compilation message

biochips.cpp:11:5: error: 'int time' redeclared as different kind of entity
   11 | int time = 0;
      |     ^~~~
In file included from /usr/include/pthread.h:24,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/gthr.h:148,
                 from /usr/include/c++/9/ext/atomicity.h:35,
                 from /usr/include/c++/9/bits/ios_base.h:39,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from biochips.cpp:1:
/usr/include/time.h:75:15: note: previous declaration 'time_t time(time_t*)'
   75 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
biochips.cpp: In function 'void dfs(int)':
biochips.cpp:14:17: warning: ISO C++ forbids incrementing a pointer of type 'time_t (*)(time_t*) throw ()' {aka 'long int (*)(long int*)'} [-Wpointer-arith]
   14 |     in[nod] = ++time;
      |                 ^~~~
biochips.cpp:14:17: error: lvalue required as increment operand
biochips.cpp:15:13: error: invalid types 'int [200005][time_t(time_t*) throw () {aka long int(long int*)}]' for array subscript
   15 |     ord[time] = nod;
      |             ^
biochips.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i = 0; i < g[nod].size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
biochips.cpp:21:18: warning: ISO C++ forbids incrementing a pointer of type 'time_t (*)(time_t*) throw ()' {aka 'long int (*)(long int*)'} [-Wpointer-arith]
   21 |     out[nod] = ++time;
      |                  ^~~~
biochips.cpp:21:18: error: lvalue required as increment operand
biochips.cpp: In function 'int main()':
biochips.cpp:37:26: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   37 |         for (i = 1; i <= time; i++)
      |                          ^~~~
biochips.cpp:41:26: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   41 |         for (i = 1; i <= time; i++)
      |                          ^~~~
biochips.cpp:48:23: error: invalid types 'int [400005][time_t(time_t*) throw () {aka long int(long int*)}]' for array subscript
   48 |     cout << dp[m][time];
      |                       ^
biochips.cpp:25:24: warning: unused variable 'k' [-Wunused-variable]
   25 |     int n, m, i, j, r, k, l, x;
      |                        ^
biochips.cpp:25:27: warning: unused variable 'l' [-Wunused-variable]
   25 |     int n, m, i, j, r, k, l, x;
      |                           ^