제출 #969026

#제출 시각아이디문제언어결과실행 시간메모리
969026Hugo1729경주 (Race) (IOI11_race)C++11
0 / 100
3 ms9564 KiB
#include <bits/stdc++.h> #include "race.h" using namespace std; vector<pair<int,int>> 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<int,int>> dfs_path(int v, int pV){ vector<pair<int,int>> sus; for(auto [w,d] : adj[v]){ if(w!=pV&&!marked[w]){ vector<pair<int,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<int,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<int,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); } } 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 'int dfs_sizes(int, int)':
race.cpp:12:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   12 |     for(auto [w,d] : adj[v]){
      |              ^
race.cpp: In function 'int find_centroid(int, int, int)':
race.cpp:23:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |     for(auto [w,d] : adj[v]){
      |              ^
race.cpp: In function 'std::vector<std::pair<int, int> > dfs_path(int, int)':
race.cpp:33:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |     for(auto [w,d] : adj[v]){
      |              ^
race.cpp:37:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             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:60:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   60 |     for(auto [w,d] : adj[c]){
      |              ^
race.cpp:68:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |             for(int i=0;i<path.size();i++){
      |                         ~^~~~~~~~~~~~
race.cpp:76:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             for(int i=0;i<path.size();i++){
      |                         ~^~~~~~~~~~~~
race.cpp:87: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]
   87 |     for(int i=0;i<sus.size();i++)cout << '{' << sus[i].first << ' ' << sus[i].second << '}';
      |                 ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...