| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 44122 | Talant | Fireworks (APIO16_fireworks) | C++17 | 6 ms | 5408 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
#define int long long
using namespace std;
typedef long long ll;
const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 7;
int n,m;
int cnt = 1;
int x,w,mn = inf;
int mx,dist[N];
int d[N],ans;
vector <pair<int,int> > g[N];
vector <int> e,vec;
void dfs (int v,int p = -1,int d = 0) {
dist[v] = d;
if (g[v].size() == 1 && v != 1)
e.pb(d),vec.pb(v);
for (auto to : g[v]) {
if (to.fr != p)
dfs(to.fr,v,d + to.sc);
}
}
void solve (int v,int cur,int p = -1) {
for (auto to : g[v]) {
if (p != to.fr) {
solve(to.fr,cur,v);
d[v] = min(d[to.fr],d[v]);
}
}
}
void calc (int v,int p = -1) {
for (auto to : g[v]) {
if (p != to.fr) {
ans += (d[to.fr] - d[v]);
calc(to.fr,v);
}
}
}
main () {
cin >> n >> m;
for (int i = 1; i < n + m; i ++) {
cin >> x >> w;
++cnt;
g[x].pb(mk(cnt,w));
g[cnt].pb(mk(x,w));
}
dfs(1);
for (int i = 0; i < e.size(); i ++) {
for (int j = 0; j < vec.size(); j ++)
d[vec[j]] = abs(dist[vec[j]] - e[i]);
solve (1,e[i]);
calc(1);
mn = min(mn,ans);
for (int j = 1; j <= cnt; j ++) {
d[j] = inf;
}
ans = 0;
}
cout << mn << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
