이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ed <<endl;
vector<vector<pair<int, int>>> adj(2e5+5);
vector<int> sz(2e5+5);
int N;
int K;
int cur = -1;
vector<int> forb(2e5+5);
int findCentroid(int n, int node, int par){
if(n == 1){
cur = node;
return 0;
}
sz[node] = 1;
bool ok = 1;
for(int i=0;i<adj[node].size();i++){
if(cur != -1){
return 0;
}
int v=adj[node][i].first;
if(v != par && !forb[v]){
sz[node] += findCentroid(n, v, node);
if(sz[v] > n / 2) ok = 0;
}
}
if(n - sz[node] > n / 2){
ok = 0;
}
if(ok){
cur = node;
}
return sz[node];
}
int ans = 2e5+5;
//map<cost, edgecount>
void dfs(int node, int par, int dist, int cost, unordered_map<int, int> &global){
int k=K;
if(cost > K){
return;
}
if(cost == k){
ans = min(ans, dist);
return;
}
if(global[k-cost] != 0){
ans = min(ans, global[k-cost]+dist);
}
for(int i=0;i<adj[node].size();i++){
int v = adj[node][i].first;
if(!forb[v] && v != par){
dfs(v,par,dist+1,cost+adj[node][i].second, global);
}
}
if(global[cost] == 0){
global[cost] = dist;
}
global[cost] = min(global[cost], dist);
}
void solve(int node){
int cnt = 0;
function<void(int, int)> mdfs = [&](int cur, int par){
cnt++;
for(int i=0;i<adj[cur].size();i++){
int v = adj[cur][i].first;
if(!forb[v] && v != par){
mdfs(v, cur);
}
}
};
mdfs(node, -1);
unordered_map<int, int> global;
cur = -1;
findCentroid(cnt, node, -1);
forb[cur] = 1;
dfs(cur, -1, 0, 0, global);
// cerr << imie(cur) imie(cnt) ed;
int me = cur;
for(int i=0;i<adj[me].size();i++){
int v = adj[me][i].first;
if(!forb[v]){
solve(v);
}
}
}
int best_path(int n, int k, int h[][2], int l[]){
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
race.cpp: In function 'int findCentroid(int, int, int)':
race.cpp:20:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i=0;i<adj[node].size();i++){
| ~^~~~~~~~~~~~~~~~~
race.cpp: In function 'void dfs(int, int, int, int, std::unordered_map<int, int>&)':
race.cpp:53:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i=0;i<adj[node].size();i++){
| ~^~~~~~~~~~~~~~~~~
race.cpp: In lambda function:
race.cpp:69:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i=0;i<adj[cur].size();i++){
| ~^~~~~~~~~~~~~~~~
race.cpp: In function 'void solve(int)':
race.cpp:84:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for(int i=0;i<adj[me].size();i++){
| ~^~~~~~~~~~~~~~~
# | 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... |