Submission #935131

#TimeUsernameProblemLanguageResultExecution timeMemory
935131cpptowinRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #define fo(i,d,c) for(int i=d;i<=c;i++) #define fod(i,c,d) for(int i=c;i>=d;i--) #define maxn 1000010 #define N 1010 #define fi first #define se second #define pb emplace_back #define en cout<<"\n"; #define int long long #define inf (int)1e18 #define pii pair<int,int> #define vii vector<pii> #define lb(x) x&-x #define bit(i,j) ((i>>j)&1) #define offbit(i,j) (i^(1<<j)) #define onbit(i,j) (i|(1<<j)) #define vi vector<int> template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;} template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;} using namespace std; const int nsqrt = 450; const int mod = 1e9 + 7; int n,K; vii ke[maxn]; int f[maxn]; // centroid decomposition bool is_remove[maxn]; int sz[maxn]; int ans = inf; int dfs_size(int u,int parent = -1) { sz[u] = 1; for(auto [v,w] : ke[u]) { if(v == parent or is_remove[v]) continue; sz[u] += dfs_size(v,u); } return sz[u]; } int dfs_centroid(int u,int tree_size,int parent = 0) { for(auto [v,w] : ke[u]) { if(v == parent or is_remove[v]) continue; if(2 * sz[v] > tree_size) return dfs_centroid(v,tree_size,u); } return u; } void dfs_dist(int u,int parent,bool get_ans,int len,int edge) { if(len > K) return; int val = f[len]; f[len] = edge; for(auto [v,w] : ke[u]) { if(v == parent or is_remove[v]) continue; dfs_dist(v,u,get_ans,len + w,edge + 1); } f[len] = val; if(get_ans) { ans = min(ans,f[K - len] + edge); } else f[len] = edge; } void build_centroid(int u) { int centroid = dfs_centroid(u,dfs_size(u)); is_remove[centroid] = 1; // do sth for(auto [v,w] : ke[centroid]) { if(is_remove[v]) continue; dfs_dist(v,centroid,1,w,1); dfs_dist(v,centroid,0,w,1); } for(auto [v,w] : ke[centroid]) { if(is_remove[v]) continue; build_centroid(v); } } main() { #define name "TASK" if(fopen(name".inp","r")) { freopen(name".inp","r",stdin); freopen(name".out","w",stdout); } ios_base::sync_with_stdio(false);cin.tie(NULL); cin >> n >> K; fo(i,1,n - 1) { int u,v,w; cin >> u >> v >> w; u++;v++; ke[u].pb(v,w); ke[v].pb(u,w); } fo(i,0,maxn - 1) f[i] = inf; build_centroid(1); cout << (ans == inf ? -1 : ans); }

Compilation message (stderr)

race.cpp:84:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   84 | main()
      | ^~~~
race.cpp: In function 'int main()':
race.cpp:89:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |        freopen(name".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
race.cpp:90:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |        freopen(name".out","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cclGfkQl.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccMLi2bk.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccMLi2bk.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