Submission #802021

# Submission time Handle Problem Language Result Execution time Memory
802021 2023-08-02T09:08:04 Z tlnk07 Naboj (COCI22_naboj) C++17
0 / 110
120 ms 12412 KB
#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)
{
	visited[x] = true;
	for(int c : vec[x])
	{
		if(!visited[c])	dfs(c);
		else	check = true;
	}
	sta.push(x);
}

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= m; ++i)
	{
		cin >> x >> y;
		vec[x].push_back(y);
		vec[y].push_back(x);
	}
	for(int i = 1; i <= n; ++i)
	{
		if(!visited[i])	
		{
			dfs(i);
			if(check)
			{
				cout << -1;
				return 0;
			}
		}
	}
	cout << sta.size() << "\n";
	while(!sta.empty())
	{
		cout << sta.top() << " 1\n";
		sta.pop();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Incorrect 2 ms 4948 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 120 ms 12412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Incorrect 2 ms 4948 KB Output isn't correct
9 Halted 0 ms 0 KB -