제출 #810555

#제출 시각아이디문제언어결과실행 시간메모리
810555AndiRFirefighting (NOI20_firefighting)C++14
3 / 100
396 ms28560 KiB
#include <iostream> #include <vector> using namespace std; typedef long long ll; const int Nmax=300000; int n, tot; ll k; struct node{ bool cov; ll dist; }v[Nmax]; int sol[Nmax]; vector <pair<int, int>> ad[Nmax]; void cmp(bool& t, ll& mx, bool nt, ll nmx){ if (t>nt || t==nt && nmx>mx){ t=nt; mx=nmx; } } void dfs(int nod, int p){ bool t=1; ll mx=0; for (int i=0; i<ad[nod].size(); i++){ if (ad[nod][i].first!=p){ dfs(ad[nod][i].first, nod); /// nu are cover if (v[ad[nod][i].first].cov==0){ ///trb sa ii se puna statie if (v[ad[nod][i].first].dist+ad[nod][i].second>k){ sol[tot++]=ad[nod][i].first; if (ad[nod][i].second>k) cmp(t, mx, 0, 0); else cmp (t, mx, 1, ad[nod][i].second); } /// i se amana statia else cmp(t, mx, 0, v[ad[nod][i].first].dist+ad[nod][i].second); } ///are cover else{ ///coverul nu cuprinde si statia curenta if (v[ad[nod][i].first].dist+ad[nod][i].second>k) cmp(t, mx, 0, 0); ///coverul cuprinde statia curenta else cmp(t, mx, 1, v[ad[nod][i].first].dist+ad[nod][i].second); } } } if (ad[nod].size()!=1 || p==-1){ v[nod].dist=mx; v[nod].cov=t; } //cout<<nod<<' '<<v[nod].cov<<' '<<v[nod].dist<<'\n'; if (t==0 && p==-1) sol[tot++]=nod; } int main() { cin>>n>>k; int a, b, d; for (int i=1; i<n; i++){ cin>>a>>b>>d; a--; b--; ad[a].push_back({b, d}); ad[b].push_back({a, d}); } dfs(0, -1); if (n==1) cout<<"1\n1"; else{ cout<<tot<<'\n'; for (int i=0; i<tot; i++) cout<<sol[i]+1<<' '; } return 0; }

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

Firefighting.cpp: In function 'void cmp(bool&, ll&, bool, ll)':
Firefighting.cpp:18:23: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   18 |     if (t>nt || t==nt && nmx>mx){
      |                 ~~~~~~^~~~~~~~~
Firefighting.cpp: In function 'void dfs(int, int)':
Firefighting.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i=0; i<ad[nod].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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...