# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666752 | neki | Naboj (COCI22_naboj) | C++14 | 563 ms | 41904 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>
#define ll long long
#define vc vector
using namespace std;
int main() {
ll n, m;cin >> n >> m;
vc<vc<ll>> out(n+1), in(n+1);
for(ll i=0;i<m;++i){
ll a, b;cin >> a >> b;
out[a].push_back(b);
in[b].push_back(a);
}
vc<ll> cntin(n+1, 0), cntout(n+1, 0);
for(ll i=1;i<=n;++i) cntin[i]=in[i].size(), cntout[i]=out[i].size();
queue<ll> q;
vc<ll> vis(n+1, 0), ch(n+1, 0);
for(ll i=1;i<=n;++i) if(cntin[i]==0 or cntout[i]==0) vis[i]=1, ch[i]=(cntin[i]==0)? 1LL:0LL, q.push(i);//, cout <<i << " ";cout << endl;
vc<ll> ans;
while(q.size()){
ll u=q.front();q.pop();
ans.emplace_back(u);
for(auto v: in[u])if(!vis[v]){
--cntout[v];
if(cntin[v]==0 or cntout[v]==0) q.push(v), ch[v]=(cntin[v]==0)? 1LL:0LL, vis[v]=1;
}
for(auto v: out[u])if(!vis[v]){
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... |