답안 #782223

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782223 2023-07-13T16:31:26 Z christinelynn Naboj (COCI22_naboj) C++17
110 / 110
552 ms 19316 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m;
vector <ll> al[200005];
ll deg[200005];
int main(){
    cin>>n>>m;
    queue<ll> q;
    for (int i=1;i<=m;i++){
        ll a,b;
        cin>>a>>b;
        al[a].push_back(b);
        deg[b]++;
    }
    vector <pair<ll,ll>> ans;
    for (int i=1;i<=n;i++){
        if (deg[i]==0) {
            q.push(i);
            ans.push_back({i,0});
        }
    }
    while(!q.empty()){
        ll u=q.front(); q.pop();
        for (auto z:al[u]){
            deg[z]--;
            if (deg[z]==0){
                ans.push_back({z,0});
                q.push(z);
            }
        }
    }
    if (ans.size()!=n) cout<<-1;
    
    else{
        cout<<ans.size()<<endl;
        for (auto z:ans){
            cout<<z.first<<" "<<z.second<<endl;
        }
    }
}

Compilation message

naboj.cpp: In function 'int main()':
naboj.cpp:33:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   33 |     if (ans.size()!=n) 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 3 ms 4988 KB Output is correct
7 Correct 2 ms 4980 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 4928 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 360 ms 16388 KB Output is correct
2 Correct 474 ms 16392 KB Output is correct
3 Correct 181 ms 10944 KB Output is correct
4 Correct 348 ms 16320 KB Output is correct
5 Correct 351 ms 16388 KB Output is correct
6 Correct 352 ms 16384 KB Output is correct
7 Correct 362 ms 16380 KB Output is correct
8 Correct 270 ms 14156 KB Output is correct
9 Correct 378 ms 16392 KB Output is correct
10 Correct 345 ms 16304 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 3 ms 4988 KB Output is correct
7 Correct 2 ms 4980 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 4928 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 360 ms 16388 KB Output is correct
16 Correct 474 ms 16392 KB Output is correct
17 Correct 181 ms 10944 KB Output is correct
18 Correct 348 ms 16320 KB Output is correct
19 Correct 351 ms 16388 KB Output is correct
20 Correct 352 ms 16384 KB Output is correct
21 Correct 362 ms 16380 KB Output is correct
22 Correct 270 ms 14156 KB Output is correct
23 Correct 378 ms 16392 KB Output is correct
24 Correct 345 ms 16304 KB Output is correct
25 Correct 227 ms 12784 KB Output is correct
26 Correct 184 ms 14628 KB Output is correct
27 Correct 255 ms 14396 KB Output is correct
28 Correct 246 ms 15224 KB Output is correct
29 Correct 130 ms 16140 KB Output is correct
30 Correct 226 ms 15040 KB Output is correct
31 Correct 41 ms 6388 KB Output is correct
32 Correct 341 ms 15660 KB Output is correct
33 Correct 497 ms 18768 KB Output is correct
34 Correct 397 ms 15976 KB Output is correct
35 Correct 552 ms 18748 KB Output is correct
36 Correct 348 ms 15584 KB Output is correct
37 Correct 494 ms 18068 KB Output is correct
38 Correct 459 ms 17280 KB Output is correct
39 Correct 509 ms 18660 KB Output is correct
40 Correct 466 ms 17680 KB Output is correct
41 Correct 471 ms 17588 KB Output is correct
42 Correct 504 ms 19176 KB Output is correct
43 Correct 372 ms 16400 KB Output is correct
44 Correct 466 ms 19316 KB Output is correct
45 Correct 350 ms 15848 KB Output is correct
46 Correct 437 ms 17660 KB Output is correct