제출 #1338766

#제출 시각아이디문제언어결과실행 시간메모리
1338766viettrungShops (NOI24_shops)C++17
0 / 100
302 ms90116 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define f(i, a, b) for(int i = a; i <= b; i++)
#define fi first
#define se second
#define mll map<ll, ll>
#define sll set<ll>
const ll du = 1e9 + 7;
const ll ars = 1e6 + 5;

// 1

int n, m;
int c[ars], num[ars];
vector<pll> adj[ars];

struct edge{
    ll u, v, w;
};

edge e[ars];

bool cmp(edge a, edge b){
    return a.w < b.w;
}

ll timcha(int a){
    while(a != c[a]) a = c[a];
    return a;
}

bool dsu(int x, int y){
    x = timcha(x);
    y = timcha(y);
    if(x == y) return false;
    if(num[x] > num[y]) swap(x, y);
    c[x] = y;
    num[y] += num[x];
    return true;
}
void mst(){
    for(int i = 1; i <= n; i++){
        num[i] = 1;
        c[i] = i;
    }
    sort(e + 1, e + 1 + m, cmp);
    int dem = 0;
    for(int i = 1; i <= m; i++){
        if(dem == (n - 1)) break;
        bool fl = dsu(e[i].u, e[i].v);
        if(fl == false) continue;
        auto[u, v, w] = e[i];
        adj[u].pb({v, w});
        adj[v].pb({u, w});
        dem++;
    }
}

char res[ars];

void dfs(int u, int p, bool f){
    if(f) res[u] = 'D';
    else res[u] = 'B';
    for(auto[v, w] : adj[u]){
        if(v == p) continue;
        dfs(v, u, !f);
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "tenshi"
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        cin >> e[i].u >> e[i].v >> e[i].w;
    }
    mst();
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ll mn = 1e18;
        for(auto[v, w] : adj[i]){
            //cout << i << " " << v << '\n';
            mn = min(mn, w);
        }
        if(mn != 1e18)
            ans = max(ans, mn);
    }
    cout << ans << '\n';
    dfs(1, 0, 0);
    for(int i = 1; i <= n; i++) cout << res[i];
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...