답안 #936968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936968 2024-03-03T06:46:15 Z 089487 Naboj (COCI22_naboj) C++14
110 / 110
190 ms 27264 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse4,abm,avx,popcnt")
#include<bits/stdc++.h>
#define int long long
#define quick ios::sync_with_stdio(0);cin.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define repd(x,a,b) for(int x=a;x>=b;x--)
#define F first
#define S second
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x.size())
#define lowbit(x) (x&-x)
using namespace std;
typedef pair<int,int> pii;
void debug(){
    cout<<"\n";
}
template<class T,class ...U>
void debug(T a,U ...b){
    cout<<a<<" ",debug(b...);
}
const int N=2e5+7;
const int INF=1e18L;
vector<int> v[N];
int out[N];
bool lgt[N];
signed main(){
    quick
    int n,m;
    cin>>n>>m;
    rep(i,1,m){
        int a,b;
        cin>>a>>b;
        v[b].eb(a);
        lgt[a]=true;
        out[a]++;
    }
    queue<int> q;
    vector<pii> ans;
    rep(i,1,n){
        if(!out[i]) q.push(i);
    }
    while(sz(q)){
        int x=q.front();
        q.pop();
        ans.eb(x,lgt[x]);
        for(int j:v[x]){
            out[j]--;
            if(!out[j]) q.push(j);
        }
    }
    if(sz(ans)!=n) cout<<"-1\n";
    else{
        cout<<sz(ans)<<"\n";
        for(pii p2:ans) cout<<p2.F<<" "<<p2.S<<"\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6520 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6496 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6584 KB Output is correct
9 Correct 3 ms 6744 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 19360 KB Output is correct
2 Correct 82 ms 19212 KB Output is correct
3 Correct 40 ms 13260 KB Output is correct
4 Correct 78 ms 20428 KB Output is correct
5 Correct 83 ms 19400 KB Output is correct
6 Correct 91 ms 19708 KB Output is correct
7 Correct 74 ms 19216 KB Output is correct
8 Correct 60 ms 17088 KB Output is correct
9 Correct 76 ms 20588 KB Output is correct
10 Correct 78 ms 19232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6520 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6496 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6584 KB Output is correct
9 Correct 3 ms 6744 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 77 ms 19360 KB Output is correct
16 Correct 82 ms 19212 KB Output is correct
17 Correct 40 ms 13260 KB Output is correct
18 Correct 78 ms 20428 KB Output is correct
19 Correct 83 ms 19400 KB Output is correct
20 Correct 91 ms 19708 KB Output is correct
21 Correct 74 ms 19216 KB Output is correct
22 Correct 60 ms 17088 KB Output is correct
23 Correct 76 ms 20588 KB Output is correct
24 Correct 78 ms 19232 KB Output is correct
25 Correct 95 ms 18604 KB Output is correct
26 Correct 91 ms 18816 KB Output is correct
27 Correct 95 ms 19380 KB Output is correct
28 Correct 104 ms 21556 KB Output is correct
29 Correct 68 ms 20844 KB Output is correct
30 Correct 106 ms 21240 KB Output is correct
31 Correct 18 ms 8944 KB Output is correct
32 Correct 103 ms 21696 KB Output is correct
33 Correct 157 ms 26848 KB Output is correct
34 Correct 110 ms 22724 KB Output is correct
35 Correct 190 ms 26296 KB Output is correct
36 Correct 88 ms 22880 KB Output is correct
37 Correct 123 ms 24956 KB Output is correct
38 Correct 133 ms 23480 KB Output is correct
39 Correct 183 ms 26308 KB Output is correct
40 Correct 145 ms 24752 KB Output is correct
41 Correct 163 ms 24320 KB Output is correct
42 Correct 187 ms 27232 KB Output is correct
43 Correct 129 ms 22256 KB Output is correct
44 Correct 184 ms 27264 KB Output is correct
45 Correct 85 ms 22464 KB Output is correct
46 Correct 150 ms 25280 KB Output is correct