Submission #533844

#TimeUsernameProblemLanguageResultExecution timeMemory
533844groshiBosses (BOI16_bosses)C++17
100 / 100
776 ms716 KiB
#include<iostream> #include<vector> #include<queue> #include<utility> using namespace std; struct wi{ vector<int> Q; int odw=0; }*w; long long wynik=1e18; int kiedy=0; int ile=0; long long mam=0; void bfs(int x) { queue<pair<int,long long> > kolejka; w[x].odw=x; kolejka.push({x,1}); while(!kolejka.empty()) { pair<int,long long> para=kolejka.front(); kolejka.pop(); ile++; mam+=para.second; for(int i=0;i<w[para.first].Q.size();i++) { int pom=w[para.first].Q[i]; if(w[pom].odw==x) continue; w[pom].odw=x; kolejka.push({pom,para.second+1}); } } } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n,s,x; cin>>n; w=new wi[n+3]; for(int i=1;i<=n;i++) { cin>>s; for(int j=0;j<s;j++) { cin>>x; w[x].Q.push_back(i); } } for(int i=1;i<=n;i++) { kiedy=i; ile=0; mam=0; bfs(i); if(ile!=n) continue; wynik=min(wynik,mam); } cout<<wynik; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'void bfs(int)':
bosses.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for(int i=0;i<w[para.first].Q.size();i++)
      |                     ~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...