# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
884426 |
2023-12-07T10:27:32 Z |
tsumondai |
Naboj (COCI22_naboj) |
C++14 |
|
157 ms |
20208 KB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME (1.0 * clock() / CLOCKS_PER_SEC)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 2e5 + 5;
const int oo = 1e9, mod = 1e9 + 7;
int n, m, k;
int indegree[N], ans[N];
vector<int> adj[N];
vector<int> topo;
queue <int> listSource;
void process() {
cin >> n >> m;
foru(i,1,m) {
int u, v;
cin >> u >> v;
adj[u].pb(v);
indegree[v]++;
}
for (int u = 1; u <= n; ++u)
if (!indegree[u]) listSource.push(u);
while (!listSource.empty()) {
int u = listSource.front();
listSource.pop();
topo.push_back(u);
for (auto v : adj[u]) {
indegree[v]--;
if (!indegree[v]) listSource.push(v);
}
}
if (topo.size() < n) {
cout << "-1";
return;
}
cout << topo.size() << '\n';
for (auto x: topo) cout << x << ' ' << 0 << '\n';
return;
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
process();
cerr << "Time elapsed: " << __TIME << " s.\n";
return 0;
}
// dont stop
Compilation message
naboj.cpp: In function 'void process()':
naboj.cpp:47:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
47 | if (topo.size() < n) {
| ~~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4952 KB |
Output is correct |
4 |
Correct |
1 ms |
4952 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
1 ms |
4968 KB |
Output is correct |
12 |
Correct |
1 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
5164 KB |
Output is correct |
14 |
Correct |
2 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
12972 KB |
Output is correct |
2 |
Correct |
74 ms |
13040 KB |
Output is correct |
3 |
Correct |
42 ms |
10460 KB |
Output is correct |
4 |
Correct |
71 ms |
15472 KB |
Output is correct |
5 |
Correct |
69 ms |
15560 KB |
Output is correct |
6 |
Correct |
70 ms |
15560 KB |
Output is correct |
7 |
Correct |
77 ms |
15532 KB |
Output is correct |
8 |
Correct |
56 ms |
13224 KB |
Output is correct |
9 |
Correct |
79 ms |
15624 KB |
Output is correct |
10 |
Correct |
69 ms |
15308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4952 KB |
Output is correct |
4 |
Correct |
1 ms |
4952 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
1 ms |
4968 KB |
Output is correct |
12 |
Correct |
1 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
5164 KB |
Output is correct |
14 |
Correct |
2 ms |
4952 KB |
Output is correct |
15 |
Correct |
70 ms |
12972 KB |
Output is correct |
16 |
Correct |
74 ms |
13040 KB |
Output is correct |
17 |
Correct |
42 ms |
10460 KB |
Output is correct |
18 |
Correct |
71 ms |
15472 KB |
Output is correct |
19 |
Correct |
69 ms |
15560 KB |
Output is correct |
20 |
Correct |
70 ms |
15560 KB |
Output is correct |
21 |
Correct |
77 ms |
15532 KB |
Output is correct |
22 |
Correct |
56 ms |
13224 KB |
Output is correct |
23 |
Correct |
79 ms |
15624 KB |
Output is correct |
24 |
Correct |
69 ms |
15308 KB |
Output is correct |
25 |
Correct |
73 ms |
15184 KB |
Output is correct |
26 |
Correct |
93 ms |
15792 KB |
Output is correct |
27 |
Correct |
83 ms |
16544 KB |
Output is correct |
28 |
Correct |
122 ms |
18144 KB |
Output is correct |
29 |
Correct |
63 ms |
15008 KB |
Output is correct |
30 |
Correct |
98 ms |
18024 KB |
Output is correct |
31 |
Correct |
16 ms |
7004 KB |
Output is correct |
32 |
Correct |
75 ms |
14884 KB |
Output is correct |
33 |
Correct |
157 ms |
19448 KB |
Output is correct |
34 |
Correct |
83 ms |
15300 KB |
Output is correct |
35 |
Correct |
140 ms |
19536 KB |
Output is correct |
36 |
Correct |
77 ms |
14688 KB |
Output is correct |
37 |
Correct |
108 ms |
18432 KB |
Output is correct |
38 |
Correct |
112 ms |
17160 KB |
Output is correct |
39 |
Correct |
129 ms |
19452 KB |
Output is correct |
40 |
Correct |
139 ms |
17920 KB |
Output is correct |
41 |
Correct |
103 ms |
17916 KB |
Output is correct |
42 |
Correct |
122 ms |
19912 KB |
Output is correct |
43 |
Correct |
89 ms |
15932 KB |
Output is correct |
44 |
Correct |
127 ms |
20208 KB |
Output is correct |
45 |
Correct |
76 ms |
15364 KB |
Output is correct |
46 |
Correct |
107 ms |
17916 KB |
Output is correct |