Submission #1137997

#TimeUsernameProblemLanguageResultExecution timeMemory
1137997adhityamvNaboj (COCI22_naboj)C++20
0 / 110
72 ms14404 KiB
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> #include <stack> using namespace std; #define int long long #define mp make_pair #define fi first #define pii pair<int,int> #define se second const int INF=1000000000000000000; const int N=200000; const int M=998244353; const int ln=20; struct Mint{ int n; Mint(int nn){ n=nn%M; } Mint(){ n=0; } Mint& operator+=(Mint const& m){ n=(n+m.n)%M; return *this; } Mint& operator*=(Mint const& m){ n=(n*m.n)%M; return *this; } Mint& operator-=(Mint const& m){ n=(n+M-m.n)%M; return *this; } friend Mint binpow(Mint a,int b){ if(b==0) return Mint(1); Mint r=binpow(a,b/2LL); r*=r; if(b%2==0) return r; r*=a; return r; } friend Mint inverse(Mint a){ return binpow(a,M-2); } Mint& operator/=(Mint const &b){ return (*this)*=inverse(b); } friend Mint operator+(Mint a,Mint const b){ return (a+=b); } friend Mint operator-(Mint a,Mint const b){ return (a-=b); } friend Mint operator*(Mint a,Mint const b){ return (a*=b); } friend Mint operator/(Mint a,Mint const b){ return (a/=b); } friend Mint operator-(Mint a){ return 0-a; } friend std::ostream& operator<<(std::ostream& os, Mint const& a){ return os << a.n; } friend std::istream& operator>>(std::istream& is, Mint& a){ return (is >> a.n); } friend bool operator==(Mint const& a,Mint const& b){ return a.n==b.n; } friend bool operator!=(Mint const& a,Mint const& b){ return a.n!=b.n; } }; template<typename T> std::ostream& operator<< (std::ostream& os,pair<T,T> p){ return os << p.fi << " " << p.se << "\n"; } void solve(){ int n,m; cin >> n >> m; vector<int> edges[n]; int indeg[n]; for(int i=0;i<n;i++) indeg[i]=0; for(int i=0;i<m;i++){ int u,v; cin >> u >> v; u--,v--; edges[u].push_back(v); indeg[v]++; } queue<int> q; for(int i=0;i<n;i++) if(indeg[i]==0) q.push(i); int cnt=0; stack<int> s; while(!q.empty()){ int u=q.front(); q.pop(); s.push(u); cnt++; for(int v:edges[u]){ indeg[v]--; if(indeg[v]==0) q.push(v); } } if(cnt!=n){ cout << -1; return; } while(!s.empty()){ cout << s.top()+1 << " " << 0 << "\n"; s.pop(); } } signed main(){ auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; //cin >> t; t=1; while(t--) solve(); auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...