답안 #782212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782212 2023-07-13T16:27:07 Z makanhulia Naboj (COCI22_naboj) C++17
25 / 110
92 ms 14884 KB
#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

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);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 14824 KB Output is correct
2 Correct 80 ms 14884 KB Output is correct
3 Correct 35 ms 7864 KB Output is correct
4 Correct 92 ms 14748 KB Output is correct
5 Correct 75 ms 14744 KB Output is correct
6 Correct 92 ms 14816 KB Output is correct
7 Correct 85 ms 14716 KB Output is correct
8 Correct 60 ms 11548 KB Output is correct
9 Correct 92 ms 14780 KB Output is correct
10 Correct 80 ms 14824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -