제출 #591556

#제출 시각아이디문제언어결과실행 시간메모리
591556Do_you_copy공장들 (JOI14_factories)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #define taskname "test" #define fi first #define se second #define pb push_back #define faster ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; using ll = long long; using pii = pair <int, int>; using pil = pair <int, ll>; using pli = pair <ll, int>; using pll = pair <ll, ll>; using ull = unsigned ll; mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count()); ll min(const ll &a, const ll &b){ return (a < b) ? a : b; } ll max(const ll &a, const ll &b){ return (a > b) ? a : b; } //const ll Mod = 1000000009; //const ll Mod2 = 999999999989; //only use when required const int maxN = 5e5 + 2; const ll inf = 0x3f3f3f3f3f3f3f3f; int n, q; int a[maxN], b[maxN]; int par[maxN]; int depth[maxN]; int subtree_size[maxN]; ll dist[maxN][20]; ll ans[maxN]; bool visited[maxN]; vector <pii> adj[maxN]; void centroid_dfs(int u, int p){ subtree_size[u] = 1; for (const auto &i: adj[u]){ if (visited[i.fi] || i.fi == p) continue; centroid_dfs(i.fi, u); subtree_size[u] += subtree_size[i.fi]; } } int find_centroid(int u, int p, int sz){ for (const auto &i: adj[u]){ if (visited[i.fi] || i.fi == p) continue; if (subtree_size[i.fi] > sz / 2) return find_centroid(i.fi, u, sz); } return u; } void find_distance(int u, int p, int c, ll d = 0){ for (const auto &i: adj[u]){ if (visited[i.fi] || i.fi == p) continue; dist[i.fi][c] = d + i.se; find_distance(i.fi, u, c, d + i.se); } } void update(int u){ int v = u; while (v){ ans[v] = min(ans[v], dist[u][depth[v]]); v = par[v]; } } ll get(int u){ ll res = inf; int v = u; while (v){ res = min(res, ans[v] + dist[u][depth[v]]); v = par[v]; } return res; } void reupdate(int u){ int v = u; while (v){ ans[u] = inf; v = par[v]; } } int build_centroid(int u, int low){ centroid_dfs(u, -1); int centroid = find_centroid(u, -1, subtree_size[u]); visited[centroid] = 1; depth[centroid] = low; find_distance(centroid, -1, low); for (const auto &i: adj[centroid]){ if (visited[i.fi]) continue; par[build_centroid(i.fi, low + 1)] = centroid; } return centroid; } void Init(){ cin >> n >> q; memset(ans, 0x3f, sizeof(ans)); for (int i = 1; i < n; ++i){ int u, v, w; cin >> u >> v >> w; adj[u + 1].pb({v + 1, w}); adj[v + 1].pb({u + 1, w}); } par[build_centroid(1, 1)] = 0; while (q--){ int s, t; cin >> s >> t; vector <int> x; for (int i = 0; i < s; ++i){ int mymindisburiedinpornlewl; cin >> mymindisburiedinpornlewl; update(mymindisburiedinpornlewl + 1); x.pb(mymindisburiedinpornlewl + 1); } ll answer = inf; for (int i = 0; i < t; ++i){ int mymindisburiedinpornlewl; cin >> mymindisburiedinpornlewl; answer = min(answer, get(mymindisburiedinpornlewl + 1)); } for (int i: x){ reupdate(i); } cout << answer << "\n"; } } int main(){ if (fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); //freopen(taskname".out", "w", stdout); } faster; ll tt = 1; //cin >> tt; while (tt--){ Init(); } }

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

factories.cpp: In function 'int main()':
factories.cpp:138:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  138 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccEekFGa.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc9cYhn9.o:factories.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccEekFGa.o: in function `main':
grader.cpp:(.text.startup+0x37d): undefined reference to `Init(int, int*, int*, int*)'
/usr/bin/ld: grader.cpp:(.text.startup+0x412): undefined reference to `Query(int, int*, int, int*)'
collect2: error: ld returned 1 exit status