# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
784340 | devariaota | Naboj (COCI22_naboj) | C++17 | 119 ms | 15116 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fi first
#define se second
#define pb push_back
#define TC int t; cin>>t; while(t--)
#define all(x) (x).begin(),(x).end()
//*AC BERSAMA ALLAH FORTIS FORTUNA ADIUVAT
const ll sez = 2e5 + 5;
ll n,m;
vector<pair<ll,ll> > arr;
vector<int> adj[sez], deg(sez,0), topo;
vector<bool> vis(sez,0);
void dfs(int u){
if(vis[u]) return;
vis[u]=1;
topo.pb(u);
for(auto i : adj[u]){
deg[i]--;
if(deg[i]==0) dfs(i);
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>m;
for(int i=1;i<=m;i++){
int u,v; cin>>u>>v;
adj[v].pb(u);
deg[u]++;
}
for(int i=1;i<=n;i++){
if(deg[i]==0 && !vis[i]){
dfs(i);
}
}
if(topo.size()!=n) cout<<"-1\n";
else{
for(int i : topo){
cout<<i<<' '<<1<<'\n';
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |