# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
118204 | songc | Designated Cities (JOI19_designated_cities) | C++14 | 455 ms | 25916 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, int> pii;
int N, Q;
vector<pii> G[202020];
int deg[202020], cnt, sum;
bool chk[202020];
LL ans[202020];
priority_queue<pii> PQ;
void d(int u, int p){
for (pii v : G[u]){
if (v.second != p){
ans[1] += v.first;
d(v.second, u);
}
}
}
void f(int u, int p, LL c){
for (pii v : G[u]) {
if (v.second != p) f(v.second, u, c-v.first);
else c += v.first;
}
ans[1] = max(ans[1], c);
}
int main(){
int u, v, x, y;
scanf("%d", &N);
for (int i=1; i<N; i++){
scanf("%d %d %d %d", &u, &v, &x, &y);
G[u].push_back(pii(y, v));
G[v].push_back(pii(x, u));
deg[u]++, deg[v]++;
sum += x+y;
}
for (int i=1; i<=N; i++){
if (deg[i] == 1){
PQ.push(pii(-G[i][0].first, i));
cnt++;
}
}
while (cnt>2){
pii T = PQ.top();
PQ.pop();
chk[T.second] = true;
for (pii it : G[T.second]){
if (!chk[it.second]){
u = it.second;
break;
}
}
deg[u]--;
if (deg[u] == 1){
for (pii it : G[u]){
if (!chk[it.second]){
PQ.push(pii(T.first-it.first, u));
break;
}
}
continue;
}
cnt--;
ans[cnt] = ans[cnt+1] - T.first;
}
d(1, 0);
f(1, 0, ans[1]);
ans[1] = sum - ans[1];
scanf("%d", &Q);
while (Q--){
scanf("%d", &u);
printf("%lld\n", ans[u]);
}
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... |