제출 #941956

#제출 시각아이디문제언어결과실행 시간메모리
9419564QT0R경주 (Race) (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<int,int>> graph[200004]; bool usun[200004]; int siz[200004]; int ans=200004; unordered_map<int,int> mp; int dlugosc; void prep(int v, int p){ siz[v]=1; for (auto u : graph[v]){ if (u.first==p || usun[u.first])continue; prep(u.first,v); siz[v]+=siz[u.first]; } } int find_centr(int v, int p, int n){ int mx_pod=0,mx_son; for (auto u : graph[v]){ if (u.first==p || usun[u.first])continue; if (mx_pod<siz[u.first]){ mx_son=u.first; mx_pod=siz[u.first]; }; } if (mx_pod*2>n)return find_centr(mx_son,v,n); else return v; } void dfs1(int v, int p, int odl, int dist){ if (mp.find(dlugosc-odl)!=mp.end())ans=min(ans,mp[dlugosc-odl]+dist); for (auto u : graph[v]){ if (u.first==p || usun[u.first])continue; dfs1(u.first,v,odl+u.second,dist+1); } } void dfs2(int v, int p, int odl, int dist){ for (auto u : graph[v]){ if (u.first==p || usun[u.first])continue; dfs2(u.first,v,odl+u.second,dist+1); } if (mp.find(odl)==mp.end())mp[odl]=dist; else mp[odl]=min(mp[odl],dist); } void dekomp(int v){ prep(v,-1); int centr=find_centr(v,-1,siz[v]); usun[centr]=true; mp.clear(); for (auto u : graph[centr]){ if (usun[u.first])continue; dfs1(u.first,centr,u.second,1); dfs2(u.first,centr,u.second,1); } if (mp.find(dlugosc)!=mp.end())ans=min(ans,mp[dlugosc]); for (auto u : graph[centr]){ if (usun[u.first])continue; dekomp(u.first); } } int best_path(int n, int k, int h[][2], int l[]){ dlugosc=k; for (int i = 0; i<n-1; i++){ graph[h[i].first].push_back({h[i].second,l[i]}); graph[h[i].second].push_back({h[i].first,l[i]}); } dekomp(0); if (ans>200000)return -1; return ans; }

컴파일 시 표준 에러 (stderr) 메시지

race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:70:14: error: request for member 'first' in '*(h + ((sizetype)(((long unsigned int)i) * 8)))', which is of non-class type 'int [2]'
   70 |   graph[h[i].first].push_back({h[i].second,l[i]});
      |              ^~~~~
race.cpp:70:37: error: request for member 'second' in '*(h + ((sizetype)(((long unsigned int)i) * 8)))', which is of non-class type 'int [2]'
   70 |   graph[h[i].first].push_back({h[i].second,l[i]});
      |                                     ^~~~~~
race.cpp:71:14: error: request for member 'second' in '*(h + ((sizetype)(((long unsigned int)i) * 8)))', which is of non-class type 'int [2]'
   71 |   graph[h[i].second].push_back({h[i].first,l[i]});
      |              ^~~~~~
race.cpp:71:38: error: request for member 'first' in '*(h + ((sizetype)(((long unsigned int)i) * 8)))', which is of non-class type 'int [2]'
   71 |   graph[h[i].second].push_back({h[i].first,l[i]});
      |                                      ^~~~~