QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#583868#8591. Shopsba1234anh0 247ms81360kbC++201.9kb2024-09-22 23:17:162024-09-22 23:17:17

Judging History

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

  • [2024-09-22 23:17:17]
  • 评测
  • 测评结果:0
  • 用时:247ms
  • 内存:81360kb
  • [2024-09-22 23:17:16]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define N 500005
#define ii pair<int,int>
#define bit(i,j) ((i>>j)&1)
#define sz(i) (int)i.size()
#define endl '\n'
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
int n, m;
struct arr
{
    int u, v, w;
};
vector<arr>vec;
namespace sub1
{
int res;
int c[N], par[N], sz[N];
vector<ii>g[N];
bool cmp(arr a, arr b)
{
    return a.w < b.w;
}
void init()
{
    for(int i = 1; i <= n; i++)
    {
        par[i] = i;
        sz[i] = 1;
    }
}
int found(int v)
{
    if(v == par[v])
        return v;
    return par[v] = found(par[v]);
}
bool union_set(int u, int v)
{
    u = found(u);
    v = found(v);
    if(u == v)
        return 0;
    if(sz[u] > sz[v])
        swap(u, v);
    par[v] = u;
    sz[u] += sz[v];
    return 1;
}
void kruskal()
{
    sort(vec.begin(), vec.end(), cmp);
    for(int i = 0; i < sz(vec); i++)
    {
        int u = vec[i].u, v = vec[i].v, w = vec[i].w;
        if(union_set(u, v))
        {
            g[u].push_back({v, w});
            g[v].push_back({u, w});
        }
    }
}
void dfs(int u, int p)
{
    int ans = INT_MAX;
    for(ii i : g[u])
    {
        int v = i.F, w = i.S;
        if(v == p)
            continue;
        ans = min(ans, w);
        dfs(v, u);
		c[v]=c[u]^1;
    }
    if(ans!=INT_MAX)
        res = max(res, ans);
}
void solve()
{
    init();
    kruskal();
    c[1] = 1;
    dfs(1, 0);
    cout << res << endl;
    for(int i = 1; i <= n; i++)
        if(c[i])
            cout << "B";
        else
            cout << "D";
}
}
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        vec.push_back({x, y, z});
    }
    sub1::solve();
}
/**
3 3
1 2 3
2 3 1
1 3 2
**/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 2ms
memory: 9808kb

input:

3 3
1 2 3
2 3 1
1 3 2

output:

2
BBD

result:

ok inconveniences = 2

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 9796kb

input:

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

output:

9
BBBDB

result:

wrong answer your claimed answer is 9, but the inconveniences of your plan is actually 11

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 247ms
memory: 81360kb

input:

500000 499999
1 2 776715136
2 3 406881694
3 4 265792290
4 5 507607272
5 6 182246639
6 7 997847597
7 8 164130256
8 9 278962226
9 10 411194641
10 11 363646402
11 12 672225656
12 13 494629089
13 14 717664153
14 15 121619271
15 16 476857704
16 17 301215244
17 18 810217743
18 19 850722975
19 20 10710274
...

output:

999999116
BDBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

result:

wrong answer your claimed answer is 999999116, but the inconveniences of your plan is actually 250041300094885

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 147ms
memory: 37044kb

input:

366489 397001
2 127909 1
7 171229 1
8 158597 1
11 282213 1
14 356007 1
15 286102 1
16 93205 1
17 260111 1
18 138962 1
20 359938 1
29 223905 1
31 357684 1
32 259968 1
34 65205 1
37 200276 1
41 83195 1
43 159858 1
48 332277 1
50 320322 1
51 338467 1
53 262785 1
55 83815 1
56 173198 1
58 169473 1
63 19...

output:

1
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

result:

wrong answer your claimed answer is 1, but the inconveniences of your plan is actually 46

Subtask #5:

score: 0
Skipped

Dependency #1:

0%