답안 #648647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648647 2022-10-07T09:37:51 Z mychecksedad Graph (BOI20_graph) C++17
0 / 100
14 ms 23892 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;


int n, m, bestb, best = MOD, val[N];
vector<pair<int, double>> g[N];
vector<bool> vis;
bool ok, o;
void dfs(int v, int p, int x){
    val[v] = x;
    vis[v] = 1;
    for(auto k: g[v]){
        int u = k.first;
        if(u == p) continue;
        int y = k.second - x;
        if(vis[u]){
            ok = ok & (y == val[u]);
        }else dfs(u, v, y);
    }
}
void solve(){
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int u, v, c; cin >> u >> v >> c;
        g[u].pb({v, c*10});
        g[v].pb({u, c*10});
    }
    o = 0;
    for(int i = -20; i <= 20; i += 1){
        ok = 1;
        vis.clear();
        vis.resize(n+1);
        for(int j = 1; j <= n; ++j){
            if(!vis[j])
                dfs(j, j, i);
        }
        o |= ok;
        double sum = 0;
        for(int j = 1; j <= n; ++j) sum += abs(val[j]);
        if(ok) if(best>sum) best=sum, bestb=i;
    }
    if(o){
        vis.clear();
        vis.resize(n+1);
        for(int j = 1; j <= n; ++j){
            if(!vis[j])
                dfs(j, j, bestb);
        }
        cout << "YES\n";
        for(int i = 1; i <= n; ++i) cout << (double) val[i]/10.0 << ' ';
    }else cout << "NO\n";
}





int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
        cout << '\n';
    }
    return 0;
 
}

Compilation message

Graph.cpp: In function 'int main()':
Graph.cpp:74:16: warning: unused variable 'aa' [-Wunused-variable]
   74 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23764 KB answer = YES
2 Correct 14 ms 23740 KB answer = YES
3 Correct 12 ms 23764 KB answer = YES
4 Correct 12 ms 23892 KB answer = NO
5 Correct 12 ms 23764 KB answer = YES
6 Correct 14 ms 23764 KB answer = YES
7 Correct 12 ms 23764 KB answer = YES
8 Correct 12 ms 23732 KB answer = YES
9 Correct 12 ms 23736 KB answer = NO
10 Correct 13 ms 23740 KB answer = YES
11 Correct 12 ms 23812 KB answer = YES
12 Correct 12 ms 23692 KB answer = NO
13 Correct 13 ms 23764 KB answer = YES
14 Correct 13 ms 23764 KB answer = YES
15 Correct 13 ms 23764 KB answer = YES
16 Correct 14 ms 23744 KB answer = YES
17 Correct 14 ms 23764 KB answer = YES
18 Incorrect 14 ms 23764 KB Sum of endpoints for edge (1; 1) differs from the expected value 1.
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23764 KB answer = YES
2 Correct 14 ms 23740 KB answer = YES
3 Correct 12 ms 23764 KB answer = YES
4 Correct 12 ms 23892 KB answer = NO
5 Correct 12 ms 23764 KB answer = YES
6 Correct 14 ms 23764 KB answer = YES
7 Correct 12 ms 23764 KB answer = YES
8 Correct 12 ms 23732 KB answer = YES
9 Correct 12 ms 23736 KB answer = NO
10 Correct 13 ms 23740 KB answer = YES
11 Correct 12 ms 23812 KB answer = YES
12 Correct 12 ms 23692 KB answer = NO
13 Correct 13 ms 23764 KB answer = YES
14 Correct 13 ms 23764 KB answer = YES
15 Correct 13 ms 23764 KB answer = YES
16 Correct 14 ms 23744 KB answer = YES
17 Correct 14 ms 23764 KB answer = YES
18 Incorrect 14 ms 23764 KB Sum of endpoints for edge (1; 1) differs from the expected value 1.
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23764 KB answer = YES
2 Correct 14 ms 23740 KB answer = YES
3 Correct 12 ms 23764 KB answer = YES
4 Correct 12 ms 23892 KB answer = NO
5 Correct 12 ms 23764 KB answer = YES
6 Correct 14 ms 23764 KB answer = YES
7 Correct 12 ms 23764 KB answer = YES
8 Correct 12 ms 23732 KB answer = YES
9 Correct 12 ms 23736 KB answer = NO
10 Correct 13 ms 23740 KB answer = YES
11 Correct 12 ms 23812 KB answer = YES
12 Correct 12 ms 23692 KB answer = NO
13 Correct 13 ms 23764 KB answer = YES
14 Correct 13 ms 23764 KB answer = YES
15 Correct 13 ms 23764 KB answer = YES
16 Correct 14 ms 23744 KB answer = YES
17 Correct 14 ms 23764 KB answer = YES
18 Incorrect 14 ms 23764 KB Sum of endpoints for edge (1; 1) differs from the expected value 1.
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23764 KB answer = YES
2 Correct 14 ms 23740 KB answer = YES
3 Correct 12 ms 23764 KB answer = YES
4 Correct 12 ms 23892 KB answer = NO
5 Correct 12 ms 23764 KB answer = YES
6 Correct 14 ms 23764 KB answer = YES
7 Correct 12 ms 23764 KB answer = YES
8 Correct 12 ms 23732 KB answer = YES
9 Correct 12 ms 23736 KB answer = NO
10 Correct 13 ms 23740 KB answer = YES
11 Correct 12 ms 23812 KB answer = YES
12 Correct 12 ms 23692 KB answer = NO
13 Correct 13 ms 23764 KB answer = YES
14 Correct 13 ms 23764 KB answer = YES
15 Correct 13 ms 23764 KB answer = YES
16 Correct 14 ms 23744 KB answer = YES
17 Correct 14 ms 23764 KB answer = YES
18 Incorrect 14 ms 23764 KB Sum of endpoints for edge (1; 1) differs from the expected value 1.
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23764 KB answer = YES
2 Correct 14 ms 23740 KB answer = YES
3 Correct 12 ms 23764 KB answer = YES
4 Correct 12 ms 23892 KB answer = NO
5 Correct 12 ms 23764 KB answer = YES
6 Correct 14 ms 23764 KB answer = YES
7 Correct 12 ms 23764 KB answer = YES
8 Correct 12 ms 23732 KB answer = YES
9 Correct 12 ms 23736 KB answer = NO
10 Correct 13 ms 23740 KB answer = YES
11 Correct 12 ms 23812 KB answer = YES
12 Correct 12 ms 23692 KB answer = NO
13 Correct 13 ms 23764 KB answer = YES
14 Correct 13 ms 23764 KB answer = YES
15 Correct 13 ms 23764 KB answer = YES
16 Correct 14 ms 23744 KB answer = YES
17 Correct 14 ms 23764 KB answer = YES
18 Incorrect 14 ms 23764 KB Sum of endpoints for edge (1; 1) differs from the expected value 1.
19 Halted 0 ms 0 KB -