5196 | 2023-04-21 20:39:45 | ZsofiaKeresztely | Dinók | cpp14 | Wrong answer 35/100 | 136ms | 23020 KiB |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g, comp;
vector<int> ind, tops, inq, op;
int n, last = -1;
void bfs(){
deque<int> q;
for (int i=1; i<=n; i++){
if (!ind[i]){
q.push_front(i);
}
}
while (!q.empty()){
int v = q.front();
q.pop_front();
if (op[v]) continue;
if (inq[v] > 0) return;
int ok = 0;
if (!inq[v]){
last -= 2;
ok = comp[v].size();
}
else{
inq[v] = 0;
for (int x : comp[v]){
if (inq[x] < 0){
inq[v]++;
}
else{
inq[x]--;
if (!inq[x]) ok++;
}
}
}
if (ok == comp[v].size()){
last += 2;
op[v] = last;
for (int x : comp[v]){
q.push_front(x);
}
for (int x : g[v]){
ind[x]--;
if (!ind[x]) q.push_back(x);
}
}
}
}
int main()
{
int m;
cin >> n >> m;
g.resize(n+1);
comp.resize(n+1);
inq.assign(n+1, -1);
ind.assign(n+1, 0);
op.resize(n+1, 0);
while (m--){
int t, a, b;
cin >> t >> a >> b;
if (t == 2){
g[a].push_back(b);
ind[b]++;
}
else{
comp[a].push_back(b);
comp[b].push_back(a);
}
}
bfs();
for (int i=1; i<=n; i++){
if (!op[i]){
cout << "NEM";
return 0;
}
}
cout << "IGEN";
for (int i=1; i<=n; i++){
cout << "\n" << op[i] << " " << op[i] + 1;
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1812 KiB | ||||
2 | Accepted | 3ms | 1968 KiB | ||||
3 | Accepted | 7ms | 3464 KiB | ||||
subtask2 | 0/5 | ||||||
4 | Wrong answer | 109ms | 20296 KiB | ||||
5 | Wrong answer | 59ms | 18796 KiB | ||||
6 | Wrong answer | 32ms | 17360 KiB | ||||
subtask3 | 0/15 | ||||||
7 | Accepted | 3ms | 2896 KiB | ||||
8 | Accepted | 3ms | 3108 KiB | ||||
9 | Accepted | 3ms | 3224 KiB | ||||
10 | Wrong answer | 2ms | 3220 KiB | ||||
11 | Wrong answer | 3ms | 3228 KiB | ||||
12 | Accepted | 3ms | 3304 KiB | ||||
subtask4 | 0/10 | ||||||
13 | Wrong answer | 3ms | 3552 KiB | ||||
14 | Wrong answer | 3ms | 3592 KiB | ||||
15 | Accepted | 3ms | 3676 KiB | ||||
16 | Accepted | 3ms | 3804 KiB | ||||
17 | Wrong answer | 3ms | 3804 KiB | ||||
subtask5 | 35/35 | ||||||
18 | Accepted | 3ms | 3808 KiB | ||||
19 | Accepted | 3ms | 4064 KiB | ||||
20 | Accepted | 136ms | 19996 KiB | ||||
21 | Accepted | 133ms | 19996 KiB | ||||
22 | Accepted | 3ms | 3968 KiB | ||||
23 | Accepted | 3ms | 4036 KiB | ||||
24 | Accepted | 108ms | 20128 KiB | ||||
subtask6 | 0/35 | ||||||
25 | Wrong answer | 112ms | 22544 KiB | ||||
26 | Wrong answer | 109ms | 22500 KiB | ||||
27 | Wrong answer | 111ms | 22500 KiB | ||||
28 | Wrong answer | 108ms | 22496 KiB | ||||
29 | Accepted | 108ms | 22756 KiB | ||||
30 | Wrong answer | 112ms | 22628 KiB | ||||
31 | Wrong answer | 108ms | 22668 KiB | ||||
32 | Accepted | 108ms | 22756 KiB | ||||
33 | Accepted | 107ms | 21692 KiB | ||||
34 | Wrong answer | 111ms | 23020 KiB | ||||
35 | Accepted | 108ms | 22500 KiB |