5197 | 2023-04-21 22:02:59 | ZsofiaKeresztely | Dinók | cpp14 | Time limit exceeded 35/100 | 601ms | 35988 KiB |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g, g2, comp;
vector<int> ind, tops, op, c;
vector<bool> inq;
int n, last = 1, cur = 0;
void dfs(int v){
c[v] = cur;
comp[cur].push_back(v);
for (int x : g2[v]){
if (c[x] < 0){
dfs(x);
}
}
}
void bfs(){
queue<int> q;
for (int i=1; i<=n; i++){
if (!ind[i]){
q.push(i);
}
}
while (!q.empty()){
int v = q.front();
q.pop();
if (op[v]) continue;
for (int x : comp[c[v]]){
if (x == v) continue;
if (!inq[x]){
inq[v] = 1;
}
}
if (!inq[v]){
for (int x : comp[c[v]]){
op[x] = last;
for (int y : g[x]){
ind[y]--;
if (!ind[y]) q.push(y);
}
}
last += 2;
}
}
}
int main()
{
int m;
cin >> n >> m;
g.resize(n+1);
g2.resize(n+1);
comp.resize(n+1);
inq.assign(n+1, 0);
ind.assign(n+1, 0);
c.assign(n+1, -1);
op.assign(n+1, 0);
while (m--){
int t, a, b;
cin >> t >> a >> b;
if (t == 2){
g[a].push_back(b);
ind[b]++;
}
else{
g2[a].push_back(b);
g2[b].push_back(a);
}
}
for (int i=1; i<=n; i++){
if (c[i] < 0){
comp.push_back({});
dfs(i);
cur++;
}
}
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 | 1692 KiB | ||||
2 | Accepted | 3ms | 1844 KiB | ||||
3 | Accepted | 8ms | 3444 KiB | ||||
subtask2 | 0/5 | ||||||
4 | Time limit exceeded | 601ms | 15492 KiB | ||||
5 | Time limit exceeded | 540ms | 15324 KiB | ||||
6 | Accepted | 78ms | 30520 KiB | ||||
subtask3 | 0/15 | ||||||
7 | Accepted | 3ms | 2844 KiB | ||||
8 | Accepted | 3ms | 3092 KiB | ||||
9 | Accepted | 3ms | 3284 KiB | ||||
10 | Wrong answer | 3ms | 3456 KiB | ||||
11 | Wrong answer | 3ms | 3828 KiB | ||||
12 | Accepted | 2ms | 3716 KiB | ||||
subtask4 | 0/10 | ||||||
13 | Accepted | 3ms | 3952 KiB | ||||
14 | Wrong answer | 2ms | 4016 KiB | ||||
15 | Accepted | 3ms | 4016 KiB | ||||
16 | Accepted | 3ms | 4032 KiB | ||||
17 | Wrong answer | 2ms | 4028 KiB | ||||
subtask5 | 35/35 | ||||||
18 | Accepted | 3ms | 3980 KiB | ||||
19 | Accepted | 3ms | 4344 KiB | ||||
20 | Accepted | 166ms | 35820 KiB | ||||
21 | Accepted | 158ms | 35892 KiB | ||||
22 | Accepted | 3ms | 4152 KiB | ||||
23 | Accepted | 4ms | 4540 KiB | ||||
24 | Accepted | 136ms | 35988 KiB | ||||
subtask6 | 0/35 | ||||||
25 | Time limit exceeded | 583ms | 17660 KiB | ||||
26 | Time limit exceeded | 566ms | 17724 KiB | ||||
27 | Time limit exceeded | 574ms | 17740 KiB | ||||
28 | Time limit exceeded | 569ms | 17752 KiB | ||||
29 | Accepted | 178ms | 33244 KiB | ||||
30 | Time limit exceeded | 564ms | 18112 KiB | ||||
31 | Time limit exceeded | 551ms | 18048 KiB | ||||
32 | Accepted | 180ms | 33984 KiB | ||||
33 | Accepted | 134ms | 35580 KiB | ||||
34 | Time limit exceeded | 583ms | 17928 KiB | ||||
35 | Time limit exceeded | 579ms | 17804 KiB |