답안 #648646

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648646 2022-10-07T09:34:23 Z mychecksedad Graph (BOI20_graph) C++17
0 / 100
15 ms 23864 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;
double best = MOD, bestb, val[N];
vector<pair<int, double>> g[N];
vector<bool> vis;
bool ok, o;
void dfs(int v, int p, double x){
    val[v] = x;
    vis[v] = 1;
    for(auto k: g[v]){
        int u = k.first;
        if(u == p) continue;
        double 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});
        g[v].pb({u, c});
    }
    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, (double)i/10.0);
        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, (double)bestb/10.0);
        cout << "YES\n";
        for(int i = 1; i <= n; ++i) cout << val[i] << ' ';
    }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:71:16: warning: unused variable 'aa' [-Wunused-variable]
   71 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23764 KB answer = YES
2 Correct 14 ms 23764 KB answer = YES
3 Correct 12 ms 23800 KB answer = YES
4 Correct 13 ms 23764 KB answer = NO
5 Correct 13 ms 23864 KB answer = YES
6 Correct 14 ms 23788 KB answer = YES
7 Correct 13 ms 23700 KB answer = YES
8 Correct 14 ms 23764 KB answer = YES
9 Correct 13 ms 23760 KB answer = NO
10 Correct 13 ms 23816 KB answer = YES
11 Correct 13 ms 23764 KB answer = YES
12 Correct 12 ms 23764 KB answer = NO
13 Correct 12 ms 23756 KB answer = YES
14 Correct 12 ms 23788 KB answer = YES
15 Correct 15 ms 23804 KB answer = YES
16 Correct 14 ms 23764 KB answer = YES
17 Correct 15 ms 23764 KB answer = YES
18 Incorrect 12 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 23764 KB answer = YES
3 Correct 12 ms 23800 KB answer = YES
4 Correct 13 ms 23764 KB answer = NO
5 Correct 13 ms 23864 KB answer = YES
6 Correct 14 ms 23788 KB answer = YES
7 Correct 13 ms 23700 KB answer = YES
8 Correct 14 ms 23764 KB answer = YES
9 Correct 13 ms 23760 KB answer = NO
10 Correct 13 ms 23816 KB answer = YES
11 Correct 13 ms 23764 KB answer = YES
12 Correct 12 ms 23764 KB answer = NO
13 Correct 12 ms 23756 KB answer = YES
14 Correct 12 ms 23788 KB answer = YES
15 Correct 15 ms 23804 KB answer = YES
16 Correct 14 ms 23764 KB answer = YES
17 Correct 15 ms 23764 KB answer = YES
18 Incorrect 12 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 23764 KB answer = YES
3 Correct 12 ms 23800 KB answer = YES
4 Correct 13 ms 23764 KB answer = NO
5 Correct 13 ms 23864 KB answer = YES
6 Correct 14 ms 23788 KB answer = YES
7 Correct 13 ms 23700 KB answer = YES
8 Correct 14 ms 23764 KB answer = YES
9 Correct 13 ms 23760 KB answer = NO
10 Correct 13 ms 23816 KB answer = YES
11 Correct 13 ms 23764 KB answer = YES
12 Correct 12 ms 23764 KB answer = NO
13 Correct 12 ms 23756 KB answer = YES
14 Correct 12 ms 23788 KB answer = YES
15 Correct 15 ms 23804 KB answer = YES
16 Correct 14 ms 23764 KB answer = YES
17 Correct 15 ms 23764 KB answer = YES
18 Incorrect 12 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 23764 KB answer = YES
3 Correct 12 ms 23800 KB answer = YES
4 Correct 13 ms 23764 KB answer = NO
5 Correct 13 ms 23864 KB answer = YES
6 Correct 14 ms 23788 KB answer = YES
7 Correct 13 ms 23700 KB answer = YES
8 Correct 14 ms 23764 KB answer = YES
9 Correct 13 ms 23760 KB answer = NO
10 Correct 13 ms 23816 KB answer = YES
11 Correct 13 ms 23764 KB answer = YES
12 Correct 12 ms 23764 KB answer = NO
13 Correct 12 ms 23756 KB answer = YES
14 Correct 12 ms 23788 KB answer = YES
15 Correct 15 ms 23804 KB answer = YES
16 Correct 14 ms 23764 KB answer = YES
17 Correct 15 ms 23764 KB answer = YES
18 Incorrect 12 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 23764 KB answer = YES
3 Correct 12 ms 23800 KB answer = YES
4 Correct 13 ms 23764 KB answer = NO
5 Correct 13 ms 23864 KB answer = YES
6 Correct 14 ms 23788 KB answer = YES
7 Correct 13 ms 23700 KB answer = YES
8 Correct 14 ms 23764 KB answer = YES
9 Correct 13 ms 23760 KB answer = NO
10 Correct 13 ms 23816 KB answer = YES
11 Correct 13 ms 23764 KB answer = YES
12 Correct 12 ms 23764 KB answer = NO
13 Correct 12 ms 23756 KB answer = YES
14 Correct 12 ms 23788 KB answer = YES
15 Correct 15 ms 23804 KB answer = YES
16 Correct 14 ms 23764 KB answer = YES
17 Correct 15 ms 23764 KB answer = YES
18 Incorrect 12 ms 23764 KB Sum of endpoints for edge (1; 1) differs from the expected value 1.
19 Halted 0 ms 0 KB -