Submission #872337

# Submission time Handle Problem Language Result Execution time Memory
872337 2023-11-12T22:20:24 Z Ahmed_Solyman Naboj (COCI22_naboj) C++14
110 / 110
452 ms 34992 KB
/*
In the name of Allah
made by: Ahmed_Solyman
*/
#include <bits/stdc++.h>
#include <ext/rope>
 
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
    return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
    cout<<(x?"YES":"NO")<<endl;
}
vector<int>adj[200005];
vector<int>vis(200005),v;
bool valid=1;
void dfs(int node){
    vis[node]=1;
    for(int i:adj[node]){
        if(!vis[i]){
            dfs(i);
        }
    }
    v.push_back(node);
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #ifndef ONLINE_JUDGE
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    #endif
    fast
    int n,m;cin>>n>>m;
    vector<pair<int,int>>e;
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;
        e.push_back({b,a});
        adj[b].push_back(a);
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(i);
        }
    }
    reverse(all(v));
    map<int,int>pos;
    for(int i=0;i<n;i++){
        pos[v[i]]=i;
    }
    for(auto i:e){
        valid&=(pos[i.first]<=pos[i.second]);
    }
    if(!valid){
        cout<<"-1"<<endl;
    }
    else{
        cout<<v.size()<<endl;
        for(auto i:v)cout<<i<<" "<<1<<"\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 1 ms 5720 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 2 ms 5720 KB Output is correct
9 Correct 2 ms 5720 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 2 ms 5976 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 1 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 234 ms 26028 KB Output is correct
2 Correct 203 ms 25980 KB Output is correct
3 Correct 96 ms 16372 KB Output is correct
4 Correct 258 ms 25940 KB Output is correct
5 Correct 200 ms 26048 KB Output is correct
6 Correct 223 ms 25988 KB Output is correct
7 Correct 188 ms 26024 KB Output is correct
8 Correct 143 ms 21628 KB Output is correct
9 Correct 209 ms 25936 KB Output is correct
10 Correct 204 ms 26052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 1 ms 5720 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 2 ms 5720 KB Output is correct
9 Correct 2 ms 5720 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 2 ms 5976 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 1 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 234 ms 26028 KB Output is correct
16 Correct 203 ms 25980 KB Output is correct
17 Correct 96 ms 16372 KB Output is correct
18 Correct 258 ms 25940 KB Output is correct
19 Correct 200 ms 26048 KB Output is correct
20 Correct 223 ms 25988 KB Output is correct
21 Correct 188 ms 26024 KB Output is correct
22 Correct 143 ms 21628 KB Output is correct
23 Correct 209 ms 25936 KB Output is correct
24 Correct 204 ms 26052 KB Output is correct
25 Correct 317 ms 29236 KB Output is correct
26 Correct 277 ms 28088 KB Output is correct
27 Correct 310 ms 31948 KB Output is correct
28 Correct 410 ms 34992 KB Output is correct
29 Correct 233 ms 25752 KB Output is correct
30 Correct 345 ms 34504 KB Output is correct
31 Correct 45 ms 9680 KB Output is correct
32 Correct 218 ms 28540 KB Output is correct
33 Correct 390 ms 33304 KB Output is correct
34 Correct 247 ms 28868 KB Output is correct
35 Correct 404 ms 33812 KB Output is correct
36 Correct 211 ms 28740 KB Output is correct
37 Correct 350 ms 33040 KB Output is correct
38 Correct 309 ms 31452 KB Output is correct
39 Correct 390 ms 33236 KB Output is correct
40 Correct 358 ms 32524 KB Output is correct
41 Correct 318 ms 32272 KB Output is correct
42 Correct 452 ms 33980 KB Output is correct
43 Correct 263 ms 29552 KB Output is correct
44 Correct 412 ms 34148 KB Output is correct
45 Correct 245 ms 28888 KB Output is correct
46 Correct 382 ms 31640 KB Output is correct