제출 #802939

#제출 시각아이디문제언어결과실행 시간메모리
802939tlnk07Naboj (COCI22_naboj)C++17
0 / 110
106 ms9492 KiB
#include<bits/stdc++.h>
using namespace std;
 
long long n, m, x, y;
vector<int> vec[200001]; 
stack<int> sta;
bool check = 0, visited[200001];
 
void dfs(int x)
{
	if(visited[x])	check = true;
	if(check)	return;
	visited[x] = true;
	for(int c : vec[x])
	{
		if(!visited[c])	dfs(c);
		else	check = true;
		if(check)	return;
	}
	sta.push(x);
}
 
int main()
{
	memset(visited, 0, sizeof(visited));
	cin >> n >> m;
	for(int i = 1; i <= m; ++i)
	{
		cin >> x >> y;
		vec[y].push_back(x);
	}
	for(int i = 1; i <= n; ++i)
	{
		if(!visited[i])	
		{
			dfs(i);
		}
	}
  	if(sta.size() < n)
    {
      cout << -1;
      return 0;
    }
	cout << n << "\n";
	while(!sta.empty())
	{
		cout << sta.top() << " 1\n";
		sta.pop();
	}
}

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

naboj.cpp: In function 'int main()':
naboj.cpp:39:18: warning: comparison of integer expressions of different signedness: 'std::stack<int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   39 |    if(sta.size() < n)
      |       ~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...