Submission #782212

#TimeUsernameProblemLanguageResultExecution timeMemory
782212makanhuliaNaboj (COCI22_naboj)C++17
25 / 110
92 ms14884 KiB
#include <bits/stdc++.h> #define LL long long using namespace std; int main() { LL n,m; scanf("%lld %lld",&n,&m); vector<LL>adj[n+5]; LL degree[n+5]; memset(degree,0,sizeof(degree)); for(LL a=1;a<=n;a++) { LL x,y; scanf("%lld %lld",&x,&y); adj[x].push_back(y); degree[y]++; } queue<LL>q; vector<LL>v; for(LL a=1;a<=n;a++) { if(!degree[a]) { q.push(a); v.push_back(a); } } while(!q.empty()) { LL x=q.front(); q.pop(); for(LL a:adj[x]) { degree[a]--; if(!degree[a]) { q.push(a); v.push_back(a); } } } if(v.size()!=n)printf("-1\n"); else{ printf("%lld\n",v.size()); for(LL a:v) { printf("%lld 0\n",a); } } }

Compilation message (stderr)

naboj.cpp: In function 'int main()':
naboj.cpp:46:14: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   46 |   if(v.size()!=n)printf("-1\n");
      |      ~~~~~~~~^~~
naboj.cpp:48:16: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   48 |     printf("%lld\n",v.size());
      |             ~~~^    ~~~~~~~~
      |                |          |
      |                |          std::vector<long long int>::size_type {aka long unsigned int}
      |                long long int
      |             %ld
naboj.cpp:7:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |   scanf("%lld %lld",&n,&m);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
naboj.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%lld %lld",&x,&y);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...