Submission #781136

# Submission time Handle Problem Language Result Execution time Memory
781136 2023-07-12T18:54:14 Z FEDIKUS Graph (BOI20_graph) C++17
58 / 100
700 ms 19048 KB
#include<bits/stdc++.h>

using namespace std;

using ll = long long;

const ll maxn=1e5+10;

vector<pair<ll,ll> > g[maxn];
bool moze=true;
bool vis[maxn];
ll val[maxn];
ll sgn[maxn];
double res[maxn];
vector<int> comp;
set<ll> a;

void dfs(ll node){
    comp.push_back(node);
    vis[node]=true;
    for(auto i:g[node]){
        if(vis[i.first]){
            if(sgn[i.first]!=sgn[node] && val[i.first]+val[node]!=i.second) moze=false;
            if(sgn[i.first]==sgn[node]){
                if(sgn[i.first]==1) a.emplace(i.second-val[node]-val[i.first]);
                else a.emplace(val[i.first]+val[node]-i.second);
            }
        }else{
            sgn[i.first]=-sgn[node];
            val[i.first]=i.second-val[node];
            dfs(i.first);
        }
    }
}

int main(){
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll u,v,c;
        cin>>u>>v>>c;
        g[u].push_back({v,c});
        g[v].push_back({u,c});
    }
    for(int i=1;i<=n;i++){
        if(vis[i]) continue;
        sgn[i]=1;
        val[i]=0;
        comp.clear();
        a.clear();
        dfs(i);
        if(a.size()>1) moze=false;
        if(a.size()==1){
            double aa=*a.begin();
            for(ll i:comp){
                res[i]=aa*sgn[i]/2+val[i];
            }
            continue;
        }
        ll best=0;
        ll curr=LLONG_MAX;
        for(ll i:comp){
            ll sum=0;
            for(ll j:comp){
                sum+=abs(val[j]-val[i]*sgn[i]*sgn[j]);
            }
            if(sum<curr){
                curr=sum;
                best=-val[i]*sgn[i];
            }
        }
        for(ll i:comp){
            res[i]=val[i]+best*sgn[i];
        }
    }
    if(moze){
        cout<<"YES\n";
        cout<<fixed<<showpoint<<setprecision(15);
        for(int i=1;i<=n;i++){
            cout<<res[i];
            cout<<" ";
        }
    }else cout<<"NO\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2652 KB answer = YES
8 Correct 2 ms 2660 KB answer = YES
9 Correct 1 ms 2660 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 2 ms 2656 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2656 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 2 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 1 ms 2660 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2652 KB answer = YES
8 Correct 2 ms 2660 KB answer = YES
9 Correct 1 ms 2660 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 2 ms 2656 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2656 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 2 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 1 ms 2660 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2648 KB answer = YES
27 Correct 2 ms 2656 KB answer = YES
28 Correct 1 ms 2656 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2772 KB answer = NO
31 Correct 2 ms 2656 KB answer = YES
32 Correct 2 ms 2656 KB answer = YES
33 Correct 1 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 1 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2652 KB answer = YES
8 Correct 2 ms 2660 KB answer = YES
9 Correct 1 ms 2660 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 2 ms 2656 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2656 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 2 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 1 ms 2660 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2648 KB answer = YES
27 Correct 2 ms 2656 KB answer = YES
28 Correct 1 ms 2656 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2772 KB answer = NO
31 Correct 2 ms 2656 KB answer = YES
32 Correct 2 ms 2656 KB answer = YES
33 Correct 1 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 1 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
37 Correct 2 ms 2648 KB answer = YES
38 Correct 2 ms 2656 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2772 KB answer = YES
41 Correct 3 ms 2668 KB answer = NO
42 Correct 3 ms 2772 KB answer = YES
43 Correct 4 ms 2772 KB answer = YES
44 Correct 2 ms 2772 KB answer = YES
45 Correct 3 ms 2772 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 3 ms 2772 KB answer = YES
48 Correct 2 ms 2664 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2652 KB answer = YES
8 Correct 2 ms 2660 KB answer = YES
9 Correct 1 ms 2660 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 2 ms 2656 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2656 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 2 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 1 ms 2660 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2648 KB answer = YES
27 Correct 2 ms 2656 KB answer = YES
28 Correct 1 ms 2656 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2772 KB answer = NO
31 Correct 2 ms 2656 KB answer = YES
32 Correct 2 ms 2656 KB answer = YES
33 Correct 1 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 1 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
37 Correct 2 ms 2648 KB answer = YES
38 Correct 2 ms 2656 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2772 KB answer = YES
41 Correct 3 ms 2668 KB answer = NO
42 Correct 3 ms 2772 KB answer = YES
43 Correct 4 ms 2772 KB answer = YES
44 Correct 2 ms 2772 KB answer = YES
45 Correct 3 ms 2772 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 3 ms 2772 KB answer = YES
48 Correct 2 ms 2664 KB answer = YES
49 Correct 144 ms 3812 KB answer = YES
50 Correct 12 ms 4212 KB answer = YES
51 Correct 148 ms 4292 KB answer = YES
52 Correct 133 ms 4052 KB answer = NO
53 Correct 4 ms 2684 KB answer = YES
54 Correct 10 ms 2928 KB answer = YES
55 Correct 49 ms 3232 KB answer = YES
56 Correct 135 ms 3668 KB answer = YES
57 Correct 29 ms 3680 KB answer = YES
58 Correct 53 ms 3580 KB answer = YES
59 Correct 10 ms 3568 KB answer = YES
60 Correct 70 ms 3704 KB answer = YES
61 Correct 6 ms 3156 KB answer = YES
62 Correct 197 ms 12944 KB answer = NO
63 Correct 113 ms 13044 KB answer = YES
64 Correct 214 ms 12984 KB answer = NO
65 Correct 111 ms 13132 KB answer = YES
66 Correct 5 ms 2772 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 1 ms 2644 KB answer = YES
7 Correct 2 ms 2652 KB answer = YES
8 Correct 2 ms 2660 KB answer = YES
9 Correct 1 ms 2660 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 2 ms 2656 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2656 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 2 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 1 ms 2660 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2648 KB answer = YES
27 Correct 2 ms 2656 KB answer = YES
28 Correct 1 ms 2656 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2772 KB answer = NO
31 Correct 2 ms 2656 KB answer = YES
32 Correct 2 ms 2656 KB answer = YES
33 Correct 1 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 1 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
37 Correct 2 ms 2648 KB answer = YES
38 Correct 2 ms 2656 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2772 KB answer = YES
41 Correct 3 ms 2668 KB answer = NO
42 Correct 3 ms 2772 KB answer = YES
43 Correct 4 ms 2772 KB answer = YES
44 Correct 2 ms 2772 KB answer = YES
45 Correct 3 ms 2772 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 3 ms 2772 KB answer = YES
48 Correct 2 ms 2664 KB answer = YES
49 Correct 144 ms 3812 KB answer = YES
50 Correct 12 ms 4212 KB answer = YES
51 Correct 148 ms 4292 KB answer = YES
52 Correct 133 ms 4052 KB answer = NO
53 Correct 4 ms 2684 KB answer = YES
54 Correct 10 ms 2928 KB answer = YES
55 Correct 49 ms 3232 KB answer = YES
56 Correct 135 ms 3668 KB answer = YES
57 Correct 29 ms 3680 KB answer = YES
58 Correct 53 ms 3580 KB answer = YES
59 Correct 10 ms 3568 KB answer = YES
60 Correct 70 ms 3704 KB answer = YES
61 Correct 6 ms 3156 KB answer = YES
62 Correct 197 ms 12944 KB answer = NO
63 Correct 113 ms 13044 KB answer = YES
64 Correct 214 ms 12984 KB answer = NO
65 Correct 111 ms 13132 KB answer = YES
66 Correct 5 ms 2772 KB answer = YES
67 Execution timed out 1061 ms 19048 KB Time limit exceeded
68 Halted 0 ms 0 KB -