#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define repp(i,n,k) for(int i=1;i<=n;i+=k)
#define repo(i,n,k) for(int i=0;i<n;i+=k)
#define pb push_back
using namespace std;
ll arr[200005];
vector<ll> adj[200005];
vector<ll> ans;
int main(){
ll m,n;cin>>m>>n;
queue<ll> q;
for(int i=1;i<=n;i++){
ll a,b;cin>>a>>b;
adj[a].push_back(b);
arr[b]++;
}
repp(i,m,1){
if(arr[i]==0) q.push(i);
}
while(!q.empty()){
ll cur=q.front();
ans.pb(cur);
q.pop();
for(ll nx:adj[cur]){
arr[nx]--;
if(arr[nx]==0) q.push(nx);
}
}
if(ans.size()!=m) cout<<"-1";
else {
cout<<ans.size()<<endl;
for(ll nx:ans){
cout<<nx<<" 0"<<endl;
}
}
}
Compilation message
naboj.cpp: In function 'int main()':
naboj.cpp:36:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
36 | if(ans.size()!=m) cout<<"-1";
| ~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
311 ms |
14876 KB |
Output is correct |
2 |
Correct |
321 ms |
14872 KB |
Output is correct |
3 |
Correct |
165 ms |
10180 KB |
Output is correct |
4 |
Correct |
324 ms |
15004 KB |
Output is correct |
5 |
Correct |
319 ms |
14952 KB |
Output is correct |
6 |
Correct |
328 ms |
14896 KB |
Output is correct |
7 |
Correct |
323 ms |
14928 KB |
Output is correct |
8 |
Correct |
256 ms |
12808 KB |
Output is correct |
9 |
Correct |
353 ms |
14896 KB |
Output is correct |
10 |
Correct |
323 ms |
14848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
311 ms |
14876 KB |
Output is correct |
16 |
Correct |
321 ms |
14872 KB |
Output is correct |
17 |
Correct |
165 ms |
10180 KB |
Output is correct |
18 |
Correct |
324 ms |
15004 KB |
Output is correct |
19 |
Correct |
319 ms |
14952 KB |
Output is correct |
20 |
Correct |
328 ms |
14896 KB |
Output is correct |
21 |
Correct |
323 ms |
14928 KB |
Output is correct |
22 |
Correct |
256 ms |
12808 KB |
Output is correct |
23 |
Correct |
353 ms |
14896 KB |
Output is correct |
24 |
Correct |
323 ms |
14848 KB |
Output is correct |
25 |
Correct |
189 ms |
12796 KB |
Output is correct |
26 |
Correct |
152 ms |
13728 KB |
Output is correct |
27 |
Correct |
187 ms |
13956 KB |
Output is correct |
28 |
Correct |
285 ms |
15096 KB |
Output is correct |
29 |
Correct |
139 ms |
14172 KB |
Output is correct |
30 |
Correct |
236 ms |
14912 KB |
Output is correct |
31 |
Correct |
37 ms |
6372 KB |
Output is correct |
32 |
Correct |
336 ms |
14080 KB |
Output is correct |
33 |
Correct |
461 ms |
17272 KB |
Output is correct |
34 |
Correct |
376 ms |
14404 KB |
Output is correct |
35 |
Correct |
451 ms |
17224 KB |
Output is correct |
36 |
Correct |
340 ms |
14140 KB |
Output is correct |
37 |
Correct |
434 ms |
16500 KB |
Output is correct |
38 |
Correct |
395 ms |
15668 KB |
Output is correct |
39 |
Correct |
454 ms |
17088 KB |
Output is correct |
40 |
Correct |
435 ms |
16208 KB |
Output is correct |
41 |
Correct |
404 ms |
16144 KB |
Output is correct |
42 |
Correct |
485 ms |
17600 KB |
Output is correct |
43 |
Correct |
366 ms |
14688 KB |
Output is correct |
44 |
Correct |
486 ms |
17876 KB |
Output is correct |
45 |
Correct |
341 ms |
14272 KB |
Output is correct |
46 |
Correct |
445 ms |
16184 KB |
Output is correct |