# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
782594 |
2023-07-14T06:18:12 Z |
kebine |
Naboj (COCI22_naboj) |
C++17 |
|
56 ms |
14532 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
ll n,m,u,v;
bool vis[200200];
vector<ll> adj[200200],ans;
ll top[200200];
queue<ll> q;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
FOR(1,i,m) {
cin >> u >> v;
adj[v].pb(u);
top[u]++;
}
FOR(1,i,n) {
if(top[i] == 0) {
q.push(i);
vis[i] = true;
}
}
while(!q.empty()) {
ll x = q.front();
q.pop();
for(auto i : adj[x]) {
top[i]--;
if(top[i] == 0 && !vis[i]) {
vis[i] = true;
ans.pb(i);
q.push(i);
}
}
}
if(ans.size() != n) {
cout << -1 << endl;
return 0;
}
for(auto i : ans) {
cout << i << " 1" << endl;
}
}
/*
5 5
3 1
2 3
4 2
5 2
5 4
*/
Compilation message
naboj.cpp: In function 'int main()':
naboj.cpp:47:17: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
47 | if(ans.size() != n) {
| ~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5032 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5036 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
14532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5032 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5036 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |