답안 #875283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
875283 2023-11-18T23:13:42 Z Cyber_Wolf Naboj (COCI22_naboj) C++17
110 / 110
190 ms 25432 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;

#define lg long long
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const lg N = 2e5+5;

vector<lg> adj[N];
lg in[N], state[N];

int main()
{
	fastio;
	lg n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++)
	{
		lg u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		in[v]++;
	}
	queue<lg> q;
	lg z = 0;
	for(int i = 1; i <= n; i++)
	{
		if(in[i])	continue;
		z++;
		q.push(i);
	}
	vector<lg> a;
	while(q.size())
	{
		lg u = q.front();
		q.pop();
		lg x = 0;
		for(auto it : adj[u])
		{
			if(!x)	a.push_back(u*2+1);
			x++;
			in[it]--;
			if(!in[it])	
			{
				q.push(it);
				z++;
			}
		}
		if(adj[u].empty())
		{
			a.push_back(u*2);
		}
	}
	if(z < n)
	{
		cout << "-1\n";
		return 0;
	}
	cout << n << '\n';
	reverse(a.begin(), a.end());
	for(auto it : a)	cout << it/2 << ' ' << it%2 << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 2 ms 8088 KB Output is correct
5 Correct 2 ms 8028 KB Output is correct
6 Correct 2 ms 8024 KB Output is correct
7 Correct 2 ms 8276 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 2 ms 8108 KB Output is correct
10 Correct 2 ms 8104 KB Output is correct
11 Correct 3 ms 8024 KB Output is correct
12 Correct 2 ms 8028 KB Output is correct
13 Correct 2 ms 8028 KB Output is correct
14 Correct 2 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 16332 KB Output is correct
2 Correct 72 ms 16484 KB Output is correct
3 Correct 33 ms 12492 KB Output is correct
4 Correct 70 ms 16328 KB Output is correct
5 Correct 75 ms 16272 KB Output is correct
6 Correct 67 ms 16328 KB Output is correct
7 Correct 69 ms 16388 KB Output is correct
8 Correct 53 ms 14588 KB Output is correct
9 Correct 67 ms 16332 KB Output is correct
10 Correct 68 ms 16352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 2 ms 8088 KB Output is correct
5 Correct 2 ms 8028 KB Output is correct
6 Correct 2 ms 8024 KB Output is correct
7 Correct 2 ms 8276 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 2 ms 8108 KB Output is correct
10 Correct 2 ms 8104 KB Output is correct
11 Correct 3 ms 8024 KB Output is correct
12 Correct 2 ms 8028 KB Output is correct
13 Correct 2 ms 8028 KB Output is correct
14 Correct 2 ms 8028 KB Output is correct
15 Correct 91 ms 16332 KB Output is correct
16 Correct 72 ms 16484 KB Output is correct
17 Correct 33 ms 12492 KB Output is correct
18 Correct 70 ms 16328 KB Output is correct
19 Correct 75 ms 16272 KB Output is correct
20 Correct 67 ms 16328 KB Output is correct
21 Correct 69 ms 16388 KB Output is correct
22 Correct 53 ms 14588 KB Output is correct
23 Correct 67 ms 16332 KB Output is correct
24 Correct 68 ms 16352 KB Output is correct
25 Correct 101 ms 19668 KB Output is correct
26 Correct 64 ms 18892 KB Output is correct
27 Correct 77 ms 20188 KB Output is correct
28 Correct 97 ms 22608 KB Output is correct
29 Correct 78 ms 18740 KB Output is correct
30 Correct 96 ms 22392 KB Output is correct
31 Correct 16 ms 10072 KB Output is correct
32 Correct 110 ms 18432 KB Output is correct
33 Correct 122 ms 24320 KB Output is correct
34 Correct 90 ms 18884 KB Output is correct
35 Correct 145 ms 24512 KB Output is correct
36 Correct 73 ms 18184 KB Output is correct
37 Correct 114 ms 23052 KB Output is correct
38 Correct 99 ms 21364 KB Output is correct
39 Correct 123 ms 24256 KB Output is correct
40 Correct 134 ms 22536 KB Output is correct
41 Correct 109 ms 22208 KB Output is correct
42 Correct 137 ms 25024 KB Output is correct
43 Correct 84 ms 19592 KB Output is correct
44 Correct 190 ms 25432 KB Output is correct
45 Correct 94 ms 18968 KB Output is correct
46 Correct 106 ms 22544 KB Output is correct