Submission #574415

# Submission time Handle Problem Language Result Execution time Memory
574415 2022-06-08T13:55:17 Z hoainiem Džumbus (COCI19_dzumbus) C++14
0 / 110
32 ms 26660 KB
#include <bits/stdc++.h>
//#pragma GCC target("popcnt")
#define fi first
#define se second
#define lc id<<1
#define rc id<<1^1
const long long inf = 1e18;
#define nmax 1008
double begintime, endtime;

using namespace std;
inline void CALC_TIME()
{
    endtime = clock();
    cout << "\nexecution time : " << (endtime - begintime + 1) / 1000 << " s";
}
typedef pair<int, int> pii;
int q, n, m, u, v, sz[nmax];
long long f[nmax][2][nmax], a[nmax];
bool ck[nmax];
vector<int> l[nmax];
vector<long long> vt;
void discover(int x, int pre)
{
    assert(!ck[x]);
    ck[x] = true;
    for (int tmp : l[x])
        if (tmp != pre)
            discover(tmp, x);
}
void dfs(int x, int pre)
{
    long long p[1008], k[1008];
    sz[x] = 1;
    for (int i = 0; i <= n + 1; i++)
        f[x][0][i] = f[x][1][i] = p[i] = k[i] = inf;
    f[x][0][0] = 0;
    f[x][1][0] = inf;
    f[x][1][1] = a[x];
    if (x == 3)
    {
        x++;
        x--;
    }
    for (int tmp : l[x])
        if (tmp != pre)
        {
            dfs(tmp, x);
            for (int i = 0; i <= sz[x]; i++)
                for (int j = 0; j <= sz[tmp]; j++)
                {
                    p[i + j] = min(p[i + j], f[x][0][i] + min(f[tmp][0][j], f[tmp][1][j]));
                    k[i + j + 2] = min(k[i + j + 2], f[x][0][i] + f[tmp][0][j] + a[x] + a[tmp]);
                    k[i + j + 1] = min(k[i + j + 1], f[x][0][i] + f[tmp][1][j] + a[x]);
                    k[i + j + 1] = min(k[i + j + 1], f[x][1][i] + f[tmp][0][j] + a[tmp]);
                }
            for (int i = 0; i <= sz[x]; i++)
                for (int j = 0; j <= sz[tmp]; j++)
                    k[i + j] = min(k[i + j], f[x][1][i] + min(f[tmp][0][j], f[tmp][1][j]));
            for (int i = 0; i <= sz[x] + sz[tmp]; i++)
            {
                f[x][0][i] = p[i];
                f[x][1][i] = k[i];
            }
            sz[x] += sz[tmp];
            f[x][0][1] = f[x][1][1] = p[1] = k[1] = inf;
        }
        f[x][0][1] = f[x][1][1] = inf;
}
int main()
{
    begintime = clock();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(ck, false, sizeof(ck));
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    while (m--)
    {
        cin >> u >> v;
        l[u].push_back(v);
        l[v].push_back(u);
    }
    for (int i = 1; i <= n; i++)
        if (!ck[i])
        {
            l[0].push_back(i);
            discover(i, 0);
        }
    a[0] = inf;
    dfs(0, 0);
    vt.push_back(0);
    vt.push_back(0);
    for (int i = 2; i <= n; i++)
        vt.push_back(f[0][0][i]);
    cin >> q;
    while (q--)
    {
        cin >> m;
        u = upper_bound(vt.begin(), vt.end(), m) - vt.begin() - 1;
        if (u == 1)
            u--;
        cout <<  u << '\n';
    }
    return 0;
}

Compilation message

dzumbus.cpp: In function 'void dfs(int, int)':
dzumbus.cpp:45:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   45 |     for (int tmp : l[x])
      |     ^~~
dzumbus.cpp:68:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   68 |         f[x][0][1] = f[x][1][1] = inf;
      |         ^
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 26660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 26660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 4064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 26660 KB Output isn't correct
2 Halted 0 ms 0 KB -