Blog of RuSun

\begin {array}{c} \mathfrak {One Problem Is Difficult} \\\\ \mathfrak {Because You Don't Know} \\\\ \mathfrak {Why It Is Diffucult} \end {array}

CF949C Data Center Maintenance

LuoGu: CF949C Data Center Maintenance

CF: C. Data Center Maintenance

可能出现一个一个推迟了一个小时后,另一个必须也要推迟。对于一份资料,如果发生这样的情况就连边。缩点,强连通分量中的点一定是一起选择的,出边后面的所有点也都是受该点影响的,选择一个没有出度的点作为选择的点,使得答案最小,选择最小的强连通分量。

查看代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <cstdio>
#include <vector>
using namespace std;
template <class Type>
void read(Type &x)
{
char c;
bool flag = false;
while ((c = getchar()) < '0' || c > '9')
c == '-' && (flag = true);
x = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 3) + (x << 1) + c - '0';
flag && (x = ~x + 1);
}
template <class Type>
void write(Type x)
{
x < 0 && (putchar('-'), x = ~x + 1);
x > 9 && (write(x / 10), 0);
putchar(x % 10 + '0');
}
template <class Type>
void chkmin (Type &x, Type k)
{
k < x && (x = k);
}
const int N = 1e5 + 10;
bool vis[N];
int n, m, h, w[N], cnt, id[N], sz[N], du[N];
int top, stk[N];
int stmp, dfn[N], low[N];
vector <int> g[N];
void tarjan (int x)
{
dfn[x] = low[x] = ++stmp;
vis[stk[++top] = x] = true;
for (int i : g[x])
if (!dfn[i])
{
tarjan(i);
chkmin(low[x], low[i]);
}
else if (vis[i])
chkmin(low[x], dfn[i]);
if (low[x] ^ dfn[x])
return;
int y;
++cnt;
do
{
vis[y = stk[top--]] = false;
sz[id[y] = cnt]++;
} while (x ^ y);
}
int main ()
{
read(n), read(m), read(h);
for (int i = 1; i <= n; i++)
read(w[i]);
for (int a, b; m; m--)
{
read(a), read(b);
(w[a] + 1) % h == w[b] && (g[a].push_back(b), 0);
(w[b] + 1) % h == w[a] && (g[b].push_back(a), 0);
}
for (int i = 1; i <= n; i++)
!dfn[i] && (tarjan(i), 0);
for (int i = 1; i <= n; i++)
for (int j : g[i])
id[i] ^ id[j] && (du[id[i]]++);
int res = -1;
for (int i = 1; i <= cnt; i++)
if (!du[i] && (!~res || sz[i] < sz[res]))
res = i;
write(sz[res]), puts("");
for (int i = 1; i <= n; i++)
id[i] == res && (write(i), putchar(' '));
return 0;
}