Submission #379098

#TimeUsernameProblemLanguageResultExecution timeMemory
379098mariowongRace (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int n,m,u,z,w,ct[1000005],sum,ans,node,sz[200005]; vector <pair<int,int> > edge[200005]; vector <pair<int,int> > v; bool vis[200005],del[200005],ok,cen[200005]; void dfs(int x){ vis[x]=true; sz[x]=1; for (int i=0;i<edge[x].size();i++){ if (!vis[edge[x][i].first]){ dfs(edge[x][i].first); sz[x]+=sz[edge[x][i].first]; } } } void find_centroid(int x,int nowsz){ if (node != -1) goto byew; cen[x]=true; for (int i=0;i<edge[x].size();i++){ if (sz[edge[x][i].first] < sz[x] && sz[edge[x][i].first]*2 > nowsz) goto gg; } if ((nowsz-sz[x])*2 <= nowsz) node=x; gg:; for (int i=0;i<edge[x].size();i++){ if (!cen[edge[x][i].first] && !del[edge[x][i].first] && node == -1) find_centroid(edge[x][i].first,nowsz); } byew:; } void ggto(int x,int dis,int num){ vis[x]=true; ok=false; sz[x]=1; for (int i=0;i<edge[x].size();i++){ if (!vis[edge[x][i].first] && !del[edge[x][i].first]){ ok=true; ggto(edge[x][i].first,dis+edge[x][i].second,num+1); sz[x]+=sz[edge[x][i].first]; } } if (!ok) v.push_back(make_pair(dis,num)); } void div_and_con(int x,int nowsz){ for (int i=0;i<n;i++){ vis[i]=false; cen[i]=false; } for (int i=1;i<=m;i++){ ct[i]=1e9; } v.clear(); sz[x]=1; for (int i=0;i<edge[x].size();i++){ if (!vis[edge[x][i].first] && !del[edge[x][i].first]){ v.clear(); ggto(edge[x][i].first,edge[x][i].second,1); for (int j=0;j<v.size();j++){ if (v[j].first <= m) ans=min(ans,ct[m-v[j].first]+v[j].second); } for (int j=0;j<v.size();j++){ if (v[j].first <= m) ct[v[j].first]=min(ct[v[j].first],v[j].second); } sz[x]+=sz[edge[x][i].first]; } } for (int i=0;i<edge[x].size();i++){ if (!del[edge[x][i].first] && sz[edge[x][i].first] > 1){ node=-1; find_centroid(edge[x][i].first,sz[edge[x][i].first]); del[node]=true; div_and_con(node,sz[edge[x][i].first]); } } } int main(){ ios::sync_with_stdio(false); cin >> n >> m; ans=1e9; for (int i=1;i<n;i++){ cin >> u >> z >> w; edge[u].push_back(make_pair(z,w)); edge[z].push_back(make_pair(u,w)); } dfs(0); for (int i=0;i<n;i++){ for (int j=0;j<edge[i].size();j++){ if (sz[edge[i][j].first] < sz[i] && sz[edge[i][j].first]*2 > n) goto out; } if ((n-sz[i])*2 <= n){ del[i]=true; div_and_con(i,n); break; } out:; } if (ans == 1e9) cout << "-1\n"; else cout << ans << "\n"; return 0; }

Compilation message (stderr)

race.cpp: In function 'void dfs(int)':
race.cpp:10: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]
   10 |  for (int i=0;i<edge[x].size();i++){
      |               ~^~~~~~~~~~~~~~~
race.cpp: In function 'void find_centroid(int, int)':
race.cpp:21: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]
   21 |  for (int i=0;i<edge[x].size();i++){
      |               ~^~~~~~~~~~~~~~~
race.cpp:28: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]
   28 |  for (int i=0;i<edge[x].size();i++){
      |               ~^~~~~~~~~~~~~~~
race.cpp: In function 'void ggto(int, int, int)':
race.cpp:36: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]
   36 |  for (int i=0;i<edge[x].size();i++){
      |               ~^~~~~~~~~~~~~~~
race.cpp: In function 'void div_and_con(int, int)':
race.cpp:55: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]
   55 |  for (int i=0;i<edge[x].size();i++){
      |               ~^~~~~~~~~~~~~~~
race.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |    for (int j=0;j<v.size();j++){
      |                 ~^~~~~~~~~
race.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |    for (int j=0;j<v.size();j++){
      |                 ~^~~~~~~~~
race.cpp:70: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]
   70 |  for (int i=0;i<edge[x].size();i++){
      |               ~^~~~~~~~~~~~~~~
race.cpp: In function 'int main()':
race.cpp:89:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |   for (int j=0;j<edge[i].size();j++){
      |                ~^~~~~~~~~~~~~~~
/tmp/ccJH89Pl.o: In function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccyYGWvn.o:grader.cpp:(.text.startup+0x0): first defined here
/tmp/ccyYGWvn.o: In function `main':
grader.cpp:(.text.startup+0x24): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status