Submission #574414

# Submission time Handle Problem Language Result Execution time Memory
574414 2022-06-08T13:54:51 Z hoainiem Džumbus (COCI19_dzumbus) C++14
0 / 110
2 ms 340 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];
    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);
    #ifndef ONLINE_JUDGE
    freopen("file.inp", "r", stdin);
    freopen("file.out", "w", stdout);
    #endif
    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:40:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   40 |     for (int tmp : l[x])
      |     ^~~
dzumbus.cpp:63:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   63 |         f[x][0][1] = f[x][1][1] = inf;
      |         ^
dzumbus.cpp: In function 'int main()':
dzumbus.cpp:72:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |     freopen("file.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dzumbus.cpp:73:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |     freopen("file.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -