5198 | 2023-04-21 22:11:08 | ZsofiaKeresztely | Dinók | cpp14 | Time limit exceeded 35/100 | 601ms | 32232 KiB |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g(100001), g2(100001), comp(100001);
vector<int> ind(100001, 0), op(100001, 0), c(100001, 0);
vector<bool> inq(100001, 0);
int n, last = 1, cur = 1;
void dfs(int v){
c[v] = cur;
comp[cur].push_back(v);
for (int x : g2[v]){
if (!c[x]){
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()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int m;
cin >> n >> m;
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]){
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 | 10ms | 17920 KiB | ||||
2 | Accepted | 8ms | 18104 KiB | ||||
3 | Accepted | 10ms | 18632 KiB | ||||
subtask2 | 0/5 | ||||||
4 | Time limit exceeded | 601ms | 14688 KiB | ||||
5 | Time limit exceeded | 573ms | 13980 KiB | ||||
6 | Accepted | 52ms | 26924 KiB | ||||
subtask3 | 0/15 | ||||||
7 | Accepted | 9ms | 18980 KiB | ||||
8 | Accepted | 9ms | 19272 KiB | ||||
9 | Accepted | 9ms | 19148 KiB | ||||
10 | Wrong answer | 9ms | 19404 KiB | ||||
11 | Wrong answer | 9ms | 19444 KiB | ||||
12 | Accepted | 9ms | 19512 KiB | ||||
subtask4 | 0/10 | ||||||
13 | Accepted | 9ms | 19700 KiB | ||||
14 | Wrong answer | 8ms | 19968 KiB | ||||
15 | Accepted | 8ms | 19832 KiB | ||||
16 | Accepted | 8ms | 20088 KiB | ||||
17 | Wrong answer | 8ms | 20288 KiB | ||||
subtask5 | 35/35 | ||||||
18 | Accepted | 9ms | 20484 KiB | ||||
19 | Accepted | 10ms | 20672 KiB | ||||
20 | Accepted | 85ms | 31600 KiB | ||||
21 | Accepted | 85ms | 31564 KiB | ||||
22 | Accepted | 9ms | 20564 KiB | ||||
23 | Accepted | 9ms | 21016 KiB | ||||
24 | Accepted | 67ms | 31408 KiB | ||||
subtask6 | 0/35 | ||||||
25 | Time limit exceeded | 556ms | 17180 KiB | ||||
26 | Time limit exceeded | 574ms | 17380 KiB | ||||
27 | Time limit exceeded | 561ms | 17472 KiB | ||||
28 | Time limit exceeded | 574ms | 17332 KiB | ||||
29 | Accepted | 118ms | 31464 KiB | ||||
30 | Time limit exceeded | 538ms | 17356 KiB | ||||
31 | Time limit exceeded | 574ms | 17260 KiB | ||||
32 | Accepted | 104ms | 31672 KiB | ||||
33 | Accepted | 78ms | 32232 KiB | ||||
34 | Time limit exceeded | 569ms | 17484 KiB | ||||
35 | Time limit exceeded | 560ms | 17612 KiB |