제출 #731172

#제출 시각아이디문제언어결과실행 시간메모리
731172ReLice구슬과 끈 (APIO14_beads)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define endl "\n" #define fr first #define sc second #define sz size() #define bc back() using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}*/ void start(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const ll inf=1e9+7; const ll mod=1e9+7; const ll N=1e3+7; vector <vector <ll>> g(N); ll d[N]; map<ll,ll> mp; map<pair<ll,ll>,ll> w; void dfs(ll v,ll pr){ for(auto i : g[v]){ if(i==pr) continue; d[i]=d[v]+1; dfs(i,v); } } void solve(){ ll i,j,q,sum=0,ans=inf,a,b,mx=-1,m,t; ll n,k; cin>>n; vector<pair<ll,pair<ll,ll>>> v; for(i=1;i<n;i++){ ll c; cin>>a>>b>>c; sum+=c; g[a].pb(b); g[b].pb(a); w[{a,b}]=w[{b,a}]=c; v.pb({c,{a,b}}); } for(i=1;i<=n;i++){ if(g[i].sz==1) mp[i]++; } sort(v.begin(),v.end()); for(i=0;i<n-1;i++){ ll c=0,c2=0,mn=inf,mn2=inf; for(auto j : g[v[i].sc.fr]){ if(j==v[i].sc.sc) continue; if(mp[j]>0){ mn=min(mn,w[{v[i].sc.fr,j}]); c++; } } for(auto j : g[v[i].sc.sc]){ if(j==v[i].sc.fr) continue; if(mp[j]>0){ mn2=min(mn2,w[{v[i].sc.sc,j}]); c2++; } } if(c%2==0 && c2%2==0){ ans=min(ans,v[i].fr); } else if(c%2==0){ ans=min(ans,v[i].fr+mn2); } else if(c2%2==0){ ans=min(ans,v[i].fr+mn); } else{ ans=min(ans,v[i].fr+mn+mn2); } } cout<<sum-ans<<endl; } signed main(){ //start(); //fre(""); ll t=1; //cin>>t; while(t--) solve(); }

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

beads.cpp: In function 'void solve()':
beads.cpp:37:10: warning: unused variable 'j' [-Wunused-variable]
   37 |     ll i,j,q,sum=0,ans=inf,a,b,mx=-1,m,t;
      |          ^
beads.cpp:37:12: warning: unused variable 'q' [-Wunused-variable]
   37 |     ll i,j,q,sum=0,ans=inf,a,b,mx=-1,m,t;
      |            ^
beads.cpp:37:32: warning: unused variable 'mx' [-Wunused-variable]
   37 |     ll i,j,q,sum=0,ans=inf,a,b,mx=-1,m,t;
      |                                ^~
beads.cpp:37:38: warning: unused variable 'm' [-Wunused-variable]
   37 |     ll i,j,q,sum=0,ans=inf,a,b,mx=-1,m,t;
      |                                      ^
beads.cpp:37:40: warning: unused variable 't' [-Wunused-variable]
   37 |     ll i,j,q,sum=0,ans=inf,a,b,mx=-1,m,t;
      |                                        ^
beads.cpp:38:10: warning: unused variable 'k' [-Wunused-variable]
   38 |     ll n,k;
      |          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...