代码块全屏测试

How To Use?

导入库文件即可

1
2
<link rel='stylesheet' href='https://cdn.jsdelivr.net/gh/MHuiG/blog-cdn@1.1.12/css/me.css'>
<script src='https://cdn.jsdelivr.net/gh/MHuiG/blog-cdn@1.1.12/js/me.js'></script>
cpp code
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main()
{
cout << "Hello, World!";
return 0;
}
python code
1
2
3
#!/usr/bin/python

print ("Hello, Python!")
code
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 <iostream>
#include <vector>

using namespace std;

const int SIZE = 5e6 + 1;

struct edge
{
int to_node, id;
edge(int t, int i): to_node(t), id(i) {}
~edge() = default;
};

vector<int> edges[SIZE];
vector<edge> querys[SIZE];
int father[SIZE], mark[SIZE], ans[SIZE];

int n, m, s;

int getfa(int x)
{
if (father[x] == x)
return x;
else
return father[x] = getfa(father[x]);
}

void tarjan(int x)
{
mark[x] = 1;
for (auto i = edges[x].begin(); i != edges[x].end(); i++)
{
if (mark[*i])
continue;
tarjan(*i);
father[*i] = x;
}
for (auto i = querys[x].begin(); i != querys[x].end(); i++)
{
int y = (*i).to_node, id = (*i).id;
if (mark[y] == 2)
ans[id] = getfa(y);
}
mark[x] = 2;
}

int main()
{
int u, v;
scanf("%d%d%d", &n, &m, &s);
for (int i = 1; i <= n; i++)
{
father[i] = i;
mark[i] = 0;
}
for (int i = 1; i < n; i++)
{
scanf("%d%d", &u, &v);
edges[u].emplace_back(v);
edges[v].emplace_back(u);
}
int x, y;
for (int i = 1; i <= m; i++)
{
scanf("%d%d", &x, &y);
if (x == y)
ans[i] = 0;
else
{
querys[x].emplace_back(edge(y, i));
querys[y].emplace_back(edge(x, i));
}
}
tarjan(s);
for (int i = 1; i <= m; i++)
printf("%d\n", ans[i]);
return 0;
}

评论