| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 114311 | tincamatei | Designated Cities (JOI19_designated_cities) | C++14 | 411 ms | 31224 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200000;
struct Edge {
int a, b, c, d;
int other(int nod) {
return a ^ b ^ nod;
}
int cost(int src) {
if(src == a)
return c;
else
return d;
}
} edges[MAX_N - 1];
vector<int> graph[1+MAX_N];
long long rez[1+MAX_N];
void calcRoot(int nod, int papa = 0) {
for(auto it: graph[nod]) {
int son = edges[it].other(nod);
if(son != papa) {
rez[1] += edges[it].cost(nod);
calcRoot(son, nod);
}
}
}
long long calcBestPathFor1(int nod, int papa = 0, long long extra = 0LL) {
long long rez = extra;
for(auto it: graph[nod]) {
int son = edges[it].other(nod);
if(son != papa) {
long long sonRez = calcBestPathFor1(son, nod, extra - edges[it].cost(nod) + edges[it].cost(son));
rez = min(rez, sonRez);
}
}
return rez;
}
int main() {
int N, Q;
int leaves = 0;
scanf("%d", &N);
for(int i = 0; i < N - 1; ++i) {
scanf("%d%d%d%d", &edges[i].a, &edges[i].b, &edges[i].c, &edges[i].d);
graph[edges[i].a].push_back(i);
graph[edges[i].b].push_back(i);
}
for(int i = 1; i <= N; ++i)
if(graph[i].size() == 1)
++leaves;
rez[1] = calcBestPathFor1(1);
calcRoot(1);
scanf("%d", &Q);
for(int i = 0; i < Q; ++i) {
int x;
scanf("%d", &x);
printf("%lld\n", rez[x]);
}
return 0;
}
컴파일 시 표준 에러 (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... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
