#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fi first
#define se second
#define pb push_back
#define TC int t; cin>>t; while(t--)
#define all(x) (x).begin(),(x).end()
//*AC BERSAMA ALLAH FORTIS FORTUNA ADIUVAT
const ll sez = 2e5 + 5;
ll n,m;
vector<pair<ll,ll> > arr;
vector<int> adj[sez], deg(sez,0), topo;
vector<bool> vis(sez,0);
void dfs(int u){
if(vis[u]) return;
vis[u]=1;
topo.pb(u);
for(auto i : adj[u]){
deg[i]--;
if(deg[i]==0) dfs(i);
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>m;
for(int i=1;i<=m;i++){
int u,v; cin>>u>>v;
adj[v].pb(u);
deg[u]++;
}
for(int i=1;i<=n;i++){
if(deg[i]==0 && !vis[i]){
dfs(i);
}
}
if(topo.size()!=n) cout<<"-1\n";
else{
cout<<topo.size()<<'\n';
for(int i : topo){
cout<<i<<' '<<1<<'\n';
}
}
return 0;
}
Compilation message
naboj.cpp: In function 'int main()':
naboj.cpp:43:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
43 | if(topo.size()!=n) cout<<"-1\n";
| ~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5844 KB |
Output is correct |
2 |
Correct |
4 ms |
5716 KB |
Output is correct |
3 |
Correct |
3 ms |
5844 KB |
Output is correct |
4 |
Correct |
3 ms |
5716 KB |
Output is correct |
5 |
Correct |
4 ms |
5716 KB |
Output is correct |
6 |
Correct |
3 ms |
5716 KB |
Output is correct |
7 |
Correct |
3 ms |
5716 KB |
Output is correct |
8 |
Correct |
3 ms |
5744 KB |
Output is correct |
9 |
Correct |
3 ms |
5716 KB |
Output is correct |
10 |
Correct |
3 ms |
5716 KB |
Output is correct |
11 |
Correct |
3 ms |
5844 KB |
Output is correct |
12 |
Correct |
3 ms |
5716 KB |
Output is correct |
13 |
Correct |
3 ms |
5716 KB |
Output is correct |
14 |
Correct |
3 ms |
5716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
12852 KB |
Output is correct |
2 |
Correct |
104 ms |
15080 KB |
Output is correct |
3 |
Correct |
46 ms |
10568 KB |
Output is correct |
4 |
Correct |
84 ms |
15244 KB |
Output is correct |
5 |
Correct |
91 ms |
15096 KB |
Output is correct |
6 |
Correct |
94 ms |
15140 KB |
Output is correct |
7 |
Correct |
85 ms |
15128 KB |
Output is correct |
8 |
Correct |
80 ms |
12964 KB |
Output is correct |
9 |
Correct |
83 ms |
15048 KB |
Output is correct |
10 |
Correct |
82 ms |
15156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5844 KB |
Output is correct |
2 |
Correct |
4 ms |
5716 KB |
Output is correct |
3 |
Correct |
3 ms |
5844 KB |
Output is correct |
4 |
Correct |
3 ms |
5716 KB |
Output is correct |
5 |
Correct |
4 ms |
5716 KB |
Output is correct |
6 |
Correct |
3 ms |
5716 KB |
Output is correct |
7 |
Correct |
3 ms |
5716 KB |
Output is correct |
8 |
Correct |
3 ms |
5744 KB |
Output is correct |
9 |
Correct |
3 ms |
5716 KB |
Output is correct |
10 |
Correct |
3 ms |
5716 KB |
Output is correct |
11 |
Correct |
3 ms |
5844 KB |
Output is correct |
12 |
Correct |
3 ms |
5716 KB |
Output is correct |
13 |
Correct |
3 ms |
5716 KB |
Output is correct |
14 |
Correct |
3 ms |
5716 KB |
Output is correct |
15 |
Correct |
100 ms |
12852 KB |
Output is correct |
16 |
Correct |
104 ms |
15080 KB |
Output is correct |
17 |
Correct |
46 ms |
10568 KB |
Output is correct |
18 |
Correct |
84 ms |
15244 KB |
Output is correct |
19 |
Correct |
91 ms |
15096 KB |
Output is correct |
20 |
Correct |
94 ms |
15140 KB |
Output is correct |
21 |
Correct |
85 ms |
15128 KB |
Output is correct |
22 |
Correct |
80 ms |
12964 KB |
Output is correct |
23 |
Correct |
83 ms |
15048 KB |
Output is correct |
24 |
Correct |
82 ms |
15156 KB |
Output is correct |
25 |
Correct |
80 ms |
15368 KB |
Output is correct |
26 |
Correct |
87 ms |
15164 KB |
Output is correct |
27 |
Correct |
104 ms |
16296 KB |
Output is correct |
28 |
Correct |
142 ms |
17956 KB |
Output is correct |
29 |
Correct |
63 ms |
14688 KB |
Output is correct |
30 |
Correct |
159 ms |
17816 KB |
Output is correct |
31 |
Correct |
20 ms |
7508 KB |
Output is correct |
32 |
Correct |
99 ms |
17528 KB |
Output is correct |
33 |
Correct |
237 ms |
20476 KB |
Output is correct |
34 |
Correct |
109 ms |
17744 KB |
Output is correct |
35 |
Correct |
153 ms |
20628 KB |
Output is correct |
36 |
Correct |
102 ms |
17420 KB |
Output is correct |
37 |
Correct |
182 ms |
19844 KB |
Output is correct |
38 |
Correct |
135 ms |
18904 KB |
Output is correct |
39 |
Correct |
195 ms |
20436 KB |
Output is correct |
40 |
Correct |
162 ms |
19468 KB |
Output is correct |
41 |
Correct |
152 ms |
19388 KB |
Output is correct |
42 |
Correct |
226 ms |
20944 KB |
Output is correct |
43 |
Correct |
125 ms |
17984 KB |
Output is correct |
44 |
Correct |
205 ms |
21028 KB |
Output is correct |
45 |
Correct |
133 ms |
17696 KB |
Output is correct |
46 |
Correct |
184 ms |
19476 KB |
Output is correct |