Submission #1030622

# Submission time Handle Problem Language Result Execution time Memory
1030622 2024-07-22T07:46:27 Z ttamx Graph (BOI20_graph) C++17
5 / 100
1 ms 600 KB
#include<bits/stdc++.h>

using namespace std;

using db = long double;
using ll = long long;

const db EPS=1e-12;
const db INVPHI=(sqrt(db(5))-1)/2;

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<vector<pair<int,int>>> adj(n);
    for(int i=0;i<m;i++){
        int u,v,w;
        cin >> u >> v >> w;
        u--,v--;
        adj[u].emplace_back(v,w);
        adj[v].emplace_back(u,w);
    }
    vector<bool> vis(n);
    vector<ll> a(n),b(n);
    vector<int> comp;
    pair<ll,ll> val;
    bool found=false;
    function<void(int)> dfs=[&](int u){
        comp.emplace_back(u);
        vis[u]=true;
        for(auto [v,w]:adj[u]){
            if(!vis[v]){
                a[v]=-a[u];
                b[v]=w-b[u];
                dfs(v);
            }else{
                if(a[u]+a[v]==0){
                    if(b[u]+b[v]!=w){
                        cout << "NO",exit(0);
                    }
                }else{
                    ll num=w-b[u]-b[v];
                    ll den=a[u]+a[v];
                    if(!found){
                        found=true;
                        val={num,den};
                    }else if(num*val.second!=val.first*den){
                        cout << "NO",exit(0);
                    }
                }
            }
        }
    };
    vector<ll> ans(n);
    for(int i=0;i<n;i++)if(!vis[i]){
        comp.clear();
        found=false;
        a[i]=1,b[i]=0;
        dfs(i);
        auto calc=[&](ll x){
            ll res=0;
            for(auto u:comp){
                res+=abs(a[u]*x+b[u]*2);
            }
            return res;
        };
        auto answer=[&](ll x){
            for(auto u:comp){
                ans[u]=a[u]*x+b[u]*2;
            }
        };
        if(found){
            answer(val.first*2/val.second);
        }else{
            db m=comp.size();
            db l=-m*2,r=m*2;
            while(r-l>EPS){
                db s=(r-l)*INVPHI;
                db l2=r-s,r2=l+s;
                if(calc(l2)<calc(r2))r=r2;
                else l=l2;
            }
            answer((l+r)/2.0);
        }
    }
    cout << fixed << setprecision(10);
    cout << "YES\n";
    for(auto x:ans)cout << db(x)/2.0 << " ";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 348 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 348 KB answer = YES
19 Correct 0 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 1 ms 348 KB answer = YES
22 Correct 0 ms 600 KB answer = NO
23 Correct 1 ms 348 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 348 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 348 KB answer = YES
19 Correct 0 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 1 ms 348 KB answer = YES
22 Correct 0 ms 600 KB answer = NO
23 Correct 1 ms 348 KB answer = NO
24 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 348 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 348 KB answer = YES
19 Correct 0 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 1 ms 348 KB answer = YES
22 Correct 0 ms 600 KB answer = NO
23 Correct 1 ms 348 KB answer = NO
24 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 348 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 348 KB answer = YES
19 Correct 0 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 1 ms 348 KB answer = YES
22 Correct 0 ms 600 KB answer = NO
23 Correct 1 ms 348 KB answer = NO
24 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 348 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 348 KB answer = YES
19 Correct 0 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 1 ms 348 KB answer = YES
22 Correct 0 ms 600 KB answer = NO
23 Correct 1 ms 348 KB answer = NO
24 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
25 Halted 0 ms 0 KB -