이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
#ifndef wambule
// #include "race.h"
#endif
const int N = 200005, K = 1000006;
int mn, globk, ak[K], fp = -1;
vector<pair<int, int>> v[N], ve;
bool bo[N];
inline void minn(int &a, int b) {
if(a == -1 || b < a) a = b;
}
int ctr(int dg, int op) {
int dr = mn - 1, y;
bool mo = 1;
for(int i = 0; i < v[dg].size(); ++i) {
if(v[dg][i].first != op && !bo[v[dg][i].first]) {
y = ctr(v[dg][i].first, dg);
if(y < 0) return y;
if(y > mn / 2) mo = 0;
dr -= y;
}
}
if(dr > mn / 2) mo = 0;
if(mo) return -dg;
return mn - dr;
}
int sra(int dg, int op) {
int dr = 1;
for(int i = 0; i < v[dg].size(); ++i) {
if(v[dg][i].first != op && !bo[v[dg][i].first]) {
dr += sra(v[dg][i].first, dg);
}
}
return dr;
}
int cntr(int x = 0) {
mn = sra(x, -1);
return -ctr(x, -1);
}
void ovo(int dg, int op, int wr, int md) {
// cout << "[ovog] " << dg << "\n";
if(md > globk) return;
ve.push_back({wr, md});
for(int i = 0; i < v[dg].size(); ++i) {
if(v[dg][i].first != op && !bo[v[dg][i].first]) {
ovo(v[dg][i].first, dg, wr + 1, md + v[dg][i].second);
}
}
}
void ama(int dg) {
// cout << "[cntr] " << dg << "\n";
bo[dg] = 1;
stack<int> vey;
for(int i = 0; i < v[dg].size(); ++i) {
if(!bo[v[dg][i].first]) {
ve.clear();
ovo(v[dg][i].first, -1, 1, v[dg][i].second);
for(int j = 0; j < ve.size(); ++j) {
// cout << "[vepm] " << ve[i].first << " " << ve[i].second << "\n";
if(ve[j].second == globk) minn(fp, ve[j].first);
else {
vey.push(ve[j].second);
if(ak[globk - ve[j].second]) {
minn(fp, ak[globk - ve[j].second] + ve[j].first);
}
}
}
for(int j = 0; j < ve.size(); ++j) {
if(ak[ve[j].second] == 0 || ak[ve[j].second] > ve[j].first) {
ak[ve[j].second] = ve[j].first;
}
}
}
}
while(vey.size()) {
ak[vey.top()] = 0;
vey.pop();
}
for(int i = 0; i < v[dg].size(); ++i) {
int x = v[dg][i].first;
if(!bo[x]) ama(cntr(x));
}
}
int best_path(int n, int k, int h[][2], int l[]) {
globk = k;
for(int i = 0; i < n; ++i) {
v[i].clear();
bo[i] = 0;
}
for(int i = 0; i < n - 1; ++i) {
v[h[i][0]].push_back({h[i][1], l[i]});
v[h[i][1]].push_back({h[i][0], l[i]});
}
ama(cntr());
return fp;
}
#ifdef wambule
mt19937_64 rnd(time(0));
long long R(long long l, long long r) {
return 1ll * rnd() % (r - l + 1) + l;
}
long long Sr(long long r) {
return R(0, r - 1);
}
void G(int n, int h[][2]) {
vector<int> v;
for(int i = 0; i < n; ++i) {
v.push_back(i);
}
random_shuffle(v.begin(), v.end());
for(int i = 0; i < n - 1; ++i) {
h[i][0] = v[R(0, i)];
h[i][1] = v[i + 1];
}
}
int h[N][2];
int l[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
srand(time(0));
// cin.get();
// int n = 11;
// int k = 12;
// int h[][2] = {0, 1, 0, 2, 2, 3, 3, 4, 4, 5, 0, 6, 6, 7, 6, 8, 8, 9, 8, 10};
// int l[] = {3, 4, 5, 4, 6, 3, 2, 5, 6, 7};
int n = 200000;
int k = 1000000;
G(n, h);
for(int i = 0; i < n - 1; ++i) {
l[i] = R(0, 1000000);
}
int rtnd = best_path(n, k, h, l);
cout << "[fnps] " << rtnd << endl;
cin.get();
return 0;
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
race.cpp:2: warning: ignoring #pragma comment [-Wunknown-pragmas]
2 | #pragma comment(linker, "/stack:200000000")
|
race.cpp: In function 'int ctr(int, int)':
race.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = 0; i < v[dg].size(); ++i) {
| ~~^~~~~~~~~~~~~~
race.cpp: In function 'int sra(int, int)':
race.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i = 0; i < v[dg].size(); ++i) {
| ~~^~~~~~~~~~~~~~
race.cpp: In function 'void ovo(int, int, int, int)':
race.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i = 0; i < v[dg].size(); ++i) {
| ~~^~~~~~~~~~~~~~
race.cpp: In function 'void ama(int)':
race.cpp:69:19: 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 < v[dg].size(); ++i) {
| ~~^~~~~~~~~~~~~~
race.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int j = 0; j < ve.size(); ++j) {
| ~~^~~~~~~~~~~
race.cpp:83:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int j = 0; j < ve.size(); ++j) {
| ~~^~~~~~~~~~~
race.cpp:94:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int i = 0; i < v[dg].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... |