제출 #574459

#제출 시각아이디문제언어결과실행 시간메모리
574459hoainiemDžumbus (COCI19_dzumbus)C++14
110 / 110
74 ms34936 KiB
#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 p[nmax][nmax], k[nmax][nmax], f[nmax][2][nmax], a[nmax]; bool ck[nmax]; vector<int> l[nmax]; vector<long long> vt; stack<int> s; 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) { sz[x] = 1; for (int i = 0; i <= n + 1; i++) f[x][0][i] = f[x][1][i] = p[x][i] = k[x][i] = inf; f[x][0][0] = 0; 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[x][i + j] = min(p[x][i + j], f[x][0][i] + min(f[tmp][0][j], f[tmp][1][j])); k[x][i + j + 2] = min(k[x][i + j + 2], f[x][0][i] + f[tmp][0][j] + a[x] + a[tmp]); k[x][i + j + 1] = min(k[x][i + j + 1], f[x][0][i] + f[tmp][1][j] + a[x]); k[x][i + j + 1] = min(k[x][i + j + 1], f[x][1][i] + f[tmp][0][j] + a[tmp]); k[x][i + j] = min(k[x][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[x][i]; f[x][1][i] = k[x][i]; } sz[x] += sz[tmp]; f[x][0][1] = f[x][1][1] = p[x][1] = k[x][1] = inf; } f[x][0][1] = f[x][1][1] = inf; } int cs[nmax]; int cmp(int x, int y) { return a[x] < a[y]; } 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); } for (int i = 1; i <= n; i++) cs[i] = i; sort(cs + 1, cs + n + 1, cmp); 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]); for (int i = n - 1; i >= 0; i--) vt[i] = min(vt[i], vt[i + 1]); 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; }

컴파일 시 표준 에러 (stderr) 메시지

dzumbus.cpp: In function 'void dfs(int, int)':
dzumbus.cpp:38:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   38 |     for (int tmp : l[x])
      |     ^~~
dzumbus.cpp:59:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   59 |         f[x][0][1] = f[x][1][1] = inf;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...