Submission #497686

#TimeUsernameProblemLanguageResultExecution timeMemory
497686XIIRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fi first #define se second #define mp make_pair #define eb emplace_back #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define FORU(i, a, b) for(int i = (a); i <= (b); ++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define IOS cin.tie(0)->sync_with_stdio(false); #define PROB "IOI11_race" void Fi(){ if(fopen(PROB".inp", "r")){ freopen(PROB".inp", "r", stdin); freopen(PROB".out", "w", stdout); } } const int INF = 1e9; const int N = 2e5 + 1; const int K = 1e6; int n, k; int H[N][2], L[N]; using pi = pair<int, int>; vector<pi> adj[N]; multiset<pi> s[N]; void enter(){ cin >> n >> k; FOR(i, 1, n) cin >> H[i][0] >> H[i][1]; FOR(i, 1, n){ cin >> L[i]; adj[H[i][0]].eb(L[i], H[i][1]); adj[H[i][1]].eb(L[i], H[i][0]); } } int ans = INF; void dfs(int u, int p = -1){ s[u].insert({0, 0}); for(auto [w, v]: adj[u]) if(v != p){ dfs(v, u); for(auto p: s[v]) if(p.fi + w <= k){ s[u].insert({p.fi + w, p.se + 1}); } else break; } for(auto [w, v]: adj[u]) if(v != p){ for(auto p: s[v]) if(p.fi + w <= k){ s[u].erase(s[u].find({p.fi + w, p.se + 1})); } else break; for(auto p: s[v]) if(p.fi + w <= k){ auto it = s[u].lower_bound({k - (p.fi + w), -1}); if(it == s[u].end()) continue; if((*it).fi == k - (p.fi + w)){ ans = min(ans, p.se + 1 + (*it).se); } } else break; for(auto p: s[v]) if(p.fi + w <= k){ s[u].insert({p.fi + w, p.se + 1}); } else break; } } int main(){ IOS; Fi(); enter(); dfs(0); if(ans == INF) cout << -1; else cout << ans; return 0; }

Compilation message (stderr)

race.cpp: In function 'void Fi()':
race.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(PROB".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
race.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(PROB".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccTGDgsA.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc13WQSy.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc13WQSy.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status