Submission #849903

#TimeUsernameProblemLanguageResultExecution timeMemory
8499031075508020060209tcPovjerenstvo (COI22_povjerenstvo)C++14
13 / 100
412 ms43540 KiB
#include<bits/stdc++.h> using namespace std; //#define int long long int n;int m; vector<int>er[500005]; int dgr[500005]; int isin[500005]; int has[500005]; signed main(){ cin>>n>>m; for(int i=1;i<=m;i++){ int a;int b; cin>>a>>b; er[b].push_back(a); dgr[a]++; } queue<int>q; for(int i=1;i<=n;i++){ if(dgr[i]==0){ q.push(i); isin[i]=1; } } while(q.size()){ int nw=q.front(); q.pop(); for(int i=0;i<er[nw].size();i++){ int v=er[nw][i]; dgr[v]--; if( isin[nw] ){ has[v]=1; } if(dgr[v]==0){ if(has[v]==0){ isin[v]=1; } q.push(v); } } } vector<int>ans; for(int i=1;i<=n;i++){ if(isin[i]){ans.push_back(i);} } cout<<ans.size()<<endl; for(int i=0;i<ans.size();i++){ cout<<ans[i]<<" "; } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i=0;i<er[nw].size();i++){
      |                 ~^~~~~~~~~~~~~~
Main.cpp:47:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 | for(int i=0;i<ans.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...