# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
804510 | Tunglam07 | Naboj (COCI22_naboj) | C++17 | 402 ms | 23920 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;
vector<long long> vec[200005], ans;
long long m ,n ,dp[200005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> m >> n;
queue<long long> q;
for(int i=1;i<=n;i++)
{
long long a ,b;
cin >> a >> b;
vec[a].push_back(b);
dp[b]++;
}
for(int i=1;i<=m;i++)
{
if(dp[i]==0)
{
q.push(i);
}
}
while(!q.empty())
{
long long id = q.front();
q.pop();
ans.push_back(id);
for(long long nx:vec[id])
{
dp[nx]--;
if(dp[nx]==0)
{
q.push(nx);
}
}
}
if(ans.size()!=m)
{
cout << -1;
}
else
{
cout << ans.size() <<endl;
for(long long nx:ans)
{
cout << nx << " " << 0 << endl;
}
}
}
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... |