제출 #969036

#제출 시각아이디문제언어결과실행 시간메모리
969036Hugo1729경주 (Race) (IOI11_race)C++17
0 / 100
3 ms9564 KiB
#include <bits/stdc++.h> #include "race.h" using namespace std; typedef long long ll; vector<pair<int,ll>> adj[200000]; bool marked[200000]={0}; int sz[200000]; int ans=300000,k=0; int dfs_sizes(int v, int pV){ sz[v]=1; for(auto [w,d] : adj[v]){ if(w!=pV&&!marked[w]){ sz[v]+=dfs_sizes(w,v); } } return sz[v]; } int find_centroid(int v, int pV, int size){ // cout << 'c' << v << ' ' << pV << ' ' << size << '\n'; for(auto [w,d] : adj[v]){ if(w!=pV&&!marked[w]&&sz[w]>size/2){ return find_centroid(w,v,size); } } return v; } vector<pair<ll,int>> dfs_path(int v, int pV){ vector<pair<ll,int>> sus; for(auto [w,d] : adj[v]){ if(w!=pV&&!marked[w]){ vector<pair<ll,int>> path = dfs_path(w,v); for(int i=0;i<path.size();i++)sus.push_back({path[i].first+d,path[i].second+1}); } } sus.push_back({0,0}); return sus; } void centroid_decomposition(int v){ int d=dfs_sizes(v,v); int c = find_centroid(v,v,d); // cout << v << ' ' << c << ' ' << d << '\n'; // for(int i=0;i<11;i++)cout << sz[i] << ' '; // cout << '\n'; marked[c]=1; // vector<pair<int,int>> sus; map<ll,int> m; m[0]=0; for(auto [w,d] : adj[c]){ // cout << 'a' << c << ' ' << w <<'\n'; if(!marked[w]){ // cout << 'w' << c << '\n'; vector<pair<ll,int>> path = dfs_path(w,v); centroid_decomposition(w); // cout << 'w' << c << '\n'; for(int i=0;i<path.size();i++){ path[i].first+=d; path[i].second++; if(k-path[i].first>=0&&m.count(k-path[i].first)){ ans=min(ans,m[k-path[i].first]+path[i].second); // cout << "jk" << c << ' ' << m[k-path[i].first]+path[i].second << ' ' << path[i].first << ' ' << path[i].second << '\n'; } } for(int i=0;i<path.size();i++){ if(m.count(path[i].first))m[path[i].first]=min(m[path[i].first],path[i].second); else m[path[i].first]=path[i].second; // sus.push_back(path[i]); } } } // sus.push_back({0,0}); // cout << "sus" << ' ' << c << ' '; // for(int i=0;i<sus.size();i++)cout << '{' << sus[i].first << ' ' << sus[i].second << '}'; // cout << '\n'; } int best_path(int N, int K, int H[][2], int L[]){ for(int i=0;i<N-1;i++){ adj[H[i][0]].push_back({H[i][1],L[i]}); adj[H[i][1]].push_back({H[i][0],L[i]}); } k=K; centroid_decomposition(0); if(ans==300000)return -1; else return ans; }

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

race.cpp: In function 'std::vector<std::pair<long long int, int> > dfs_path(int, int)':
race.cpp:38:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             for(int i=0;i<path.size();i++)sus.push_back({path[i].first+d,path[i].second+1});
      |                         ~^~~~~~~~~~~~
race.cpp: In function 'void centroid_decomposition(int)':
race.cpp:69:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             for(int i=0;i<path.size();i++){
      |                         ~^~~~~~~~~~~~
race.cpp:78:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |             for(int i=0;i<path.size();i++){
      |                         ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...