# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
782564 |
2023-07-14T05:19:55 Z |
kebine |
Naboj (COCI22_naboj) |
C++17 |
|
383 ms |
19712 KB |
#include<bits/stdc++.h>
using namespace std;
#define ioss ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
int n, m;
vector<int> adj[200004];
bool vis[200004];
int cnt[200004];
vector<int> st;
void toposort(int u) {
if(vis[u]) return;
vis[u] = 1;
for(auto v : adj[u]) {
cnt[v]--;
if(!vis[v] && cnt[v] == 0) toposort(v);
}
st.push_back(u);
}
int main() {
ioss;
cin >> n >> m;
set<int> tmp;
for(int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
tmp.insert(a);
adj[b].pb(a);
cnt[a]++;
}
for(int i = 1; i <= n; i++) {
if(!vis[i] && cnt[i] == 0) toposort(i);
// cout << cnt[i] << endl;
}
bool ok = 1;
for(int i = 1; i <= n; i++) {
if(!vis[i]) {
ok = 0;
break;
}
}
if(!ok) {
cout << -1 << endl;
return 0;
}
cout << st.size() << endl;
while(!st.empty()) {
int u = st.back();
st.pop_back();
if(tmp.count(u)) cout << u << " " << 1 << endl;
else cout << u << " " << 0 << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
383 ms |
19712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |