# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
704932 |
2023-03-03T06:56:26 Z |
Cookie197 |
Naboj (COCI22_naboj) |
C++17 |
|
243 ms |
15228 KB |
#pragma GCC optimize("O4,unroll-loops")
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define endl "\n"
#define mp make_pair
#define out(x) cout << #x << " = " << x << endl
int n,m,deg[200005],tag[200005];
vector<int> adj[200005];
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>m;
for (int i=1;i<=m;i++){
int a,b; cin>>a>>b;
adj[b].push_back(a);
deg[a]++;
}
queue<int> q; vector<int> ans;
for (int i=1;i<=n;i++) if (deg[i] == 0) q.push(i);
while(q.size()){
int node = q.front();
q.pop();
ans.push_back(node);
for (int u:adj[node]){
deg[u]--;
if (deg[u] == 0) q.push(u);
}
}
if (ans.size() == n){
cout<<n<<endl;
for (int u:ans) cout<<u<<" "<<1<<endl;
}else cout<<-1<<endl;
}
Compilation message
naboj.cpp: In function 'int main()':
naboj.cpp:37:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
37 | if (ans.size() == n){
| ~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
5008 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
5000 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
13084 KB |
Output is correct |
2 |
Correct |
110 ms |
12800 KB |
Output is correct |
3 |
Correct |
63 ms |
9144 KB |
Output is correct |
4 |
Correct |
105 ms |
12868 KB |
Output is correct |
5 |
Correct |
111 ms |
12860 KB |
Output is correct |
6 |
Correct |
113 ms |
12856 KB |
Output is correct |
7 |
Correct |
102 ms |
12884 KB |
Output is correct |
8 |
Correct |
82 ms |
11060 KB |
Output is correct |
9 |
Correct |
131 ms |
12812 KB |
Output is correct |
10 |
Correct |
111 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
5008 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
5000 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
106 ms |
13084 KB |
Output is correct |
16 |
Correct |
110 ms |
12800 KB |
Output is correct |
17 |
Correct |
63 ms |
9144 KB |
Output is correct |
18 |
Correct |
105 ms |
12868 KB |
Output is correct |
19 |
Correct |
111 ms |
12860 KB |
Output is correct |
20 |
Correct |
113 ms |
12856 KB |
Output is correct |
21 |
Correct |
102 ms |
12884 KB |
Output is correct |
22 |
Correct |
82 ms |
11060 KB |
Output is correct |
23 |
Correct |
131 ms |
12812 KB |
Output is correct |
24 |
Correct |
111 ms |
12892 KB |
Output is correct |
25 |
Correct |
115 ms |
10220 KB |
Output is correct |
26 |
Correct |
114 ms |
11588 KB |
Output is correct |
27 |
Correct |
132 ms |
11728 KB |
Output is correct |
28 |
Correct |
171 ms |
12032 KB |
Output is correct |
29 |
Correct |
93 ms |
11776 KB |
Output is correct |
30 |
Correct |
159 ms |
11976 KB |
Output is correct |
31 |
Correct |
20 ms |
5920 KB |
Output is correct |
32 |
Correct |
125 ms |
15016 KB |
Output is correct |
33 |
Correct |
243 ms |
15192 KB |
Output is correct |
34 |
Correct |
137 ms |
14972 KB |
Output is correct |
35 |
Correct |
214 ms |
15168 KB |
Output is correct |
36 |
Correct |
115 ms |
15056 KB |
Output is correct |
37 |
Correct |
206 ms |
15068 KB |
Output is correct |
38 |
Correct |
168 ms |
14992 KB |
Output is correct |
39 |
Correct |
229 ms |
15116 KB |
Output is correct |
40 |
Correct |
185 ms |
14916 KB |
Output is correct |
41 |
Correct |
171 ms |
15056 KB |
Output is correct |
42 |
Correct |
213 ms |
15228 KB |
Output is correct |
43 |
Correct |
150 ms |
14956 KB |
Output is correct |
44 |
Correct |
217 ms |
15144 KB |
Output is correct |
45 |
Correct |
129 ms |
14996 KB |
Output is correct |
46 |
Correct |
195 ms |
14956 KB |
Output is correct |