QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745454#9623. 合成大西瓜Tobo#WA 1ms5664kbC++202.8kb2024-11-14 10:04:392024-11-14 10:04:40

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 10:04:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5664kb
  • [2024-11-14 10:04:39]
  • 提交

answer

/*
洛谷 P3388 【模板】割点(割顶)
*/
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int n, m; // n:点数 m:边数
int dfn[100001], low[100001], a[100001], siz[100001], ssiz[100001], inde, res;
// dfn:记录每个点的时间戳
// low:能不经过父亲到达最小的编号,inde:时间戳,res:答案数量
bool vis[100001], flag[100001]; // flag: 答案 vis:标记是否重复
vector<int> edge[100001];       // 存图用的

void Tarjan(int u, int father)
{                             // u 当前点的编号,father 自己爸爸的编号
    vis[u] = true;            // 标记
    low[u] = dfn[u] = ++inde; // 打上时间戳
    int child = 0;            // 每一个点儿子数量
    siz[u] = 1;
    for (auto v : edge[u])
    { // 访问这个点的所有邻居 (C++11)
        if (!vis[v])
        {
            child++;      // 多了一个儿子
            Tarjan(v, u); // 继续
            siz[u] += siz[v];
            low[u] = min(low[u], low[v]); // 更新能到的最小节点编号
            if (father != u && low[v] >= dfn[u] && !flag[u])
            { // 主要代码
                // 如果不是自己,且不通过父亲返回的最小点符合割点的要求,并且没有被标记过
                // 要求即为:删了父亲连不上去了,即为最多连到父亲
                flag[u] = true;
                ssiz[u] += siz[v];
                res++; // 记录答案
            }
        }
        else if (v != father)
        {
            // 如果这个点不是自己的父亲,更新能到的最小节点编号
            low[u] = min(low[u], dfn[v]);
        }
    }
    // 主要代码,自己的话需要 2 个儿子才可以
    if (father == u && child >= 2 && !flag[u])
    {
        flag[u] = true;
        res++; // 记录答案
    }
}

int main()
{
    cin >> n >> m; // 读入数据
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    if (n == 1)
    {
        cout << a[1] << '\n';
        exit(0);
    }
    for (int i = 1; i <= m; i++)
    { // 注意点是从 1 开始的
        int x, y;
        cin >> x >> y;
        edge[x].push_back(y);
        edge[y].push_back(x);
    } // 使用 vector 存图
    Tarjan(1, 1);
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (!flag[i] and edge[i].size() >= 2)
            ans = max(ans, a[i]);
        else if (ssiz[i] % 2 == 1)
            ans = max(ans, a[i]);
    }
    map<int, int> cnt;
    for (int i = 1; i <= n; i++)
        if (edge[i].size() == 1 or !flag[i])
            cnt[a[i]]++;
    for (auto &[x, y] : cnt)
        if (y >= 2)
            ans = max(ans, x);
    cout << ans << '\n';
    return 0;
}
/*
7 7
1 1 2 3 1 2 1
1 2
2 3
1 3
2 4
2 5
5 6
5 7

1 0
1

3 2
3 2 3
1 2
2 3
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5644kb

input:

7 9
1 4 1 3 3 6 7
5 4
3 6
3 4
2 3
5 2
2 6
6 7
5 1
4 6

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

5 7
1 5 3 1 4
3 5
1 3
5 1
1 4
5 4
2 4
3 2

output:

5

result:

ok single line: '5'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

7 7
2 4 2 3 3 6 7
5 1
2 6
5 3
4 6
1 6
1 2
2 7

output:

6

result:

ok single line: '6'

Test #4:

score: 0
Accepted
time: 1ms
memory: 5588kb

input:

3 2
2 2 2
2 3
1 3

output:

2

result:

ok single line: '2'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3828kb

input:

5 5
3 1 2 4 5
3 2
2 4
3 5
5 1
2 5

output:

5

result:

ok single line: '5'

Test #6:

score: 0
Accepted
time: 1ms
memory: 5664kb

input:

7 9
3 2 3 5 2 6 7
7 4
5 4
5 6
1 7
1 6
2 3
7 6
6 4
4 2

output:

7

result:

ok single line: '7'

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 5580kb

input:

3 2
1 2 3
3 1
2 1

output:

0

result:

wrong answer 1st lines differ - expected: '2', found: '0'