Submission #781141

# Submission time Handle Problem Language Result Execution time Memory
781141 2023-07-12T19:17:27 Z FEDIKUS Graph (BOI20_graph) C++17
5 / 100
3 ms 2656 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);
        }
    }
}

ll range(int l,int r,vector<ll> &arr){
    return arr[r]-(l>0 ? arr[l-1]:0);
}

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;
        }

        pair<ll,int> best={LLONG_MAX,0};

        vector<int> kandidati;
        for(ll i:comp) kandidati.push_back(-val[i]*sgn[i]);
        sort(kandidati.begin(),kandidati.end());

        vector<int> poz;
        vector<int> neg;
        for(int i:comp){
            if(sgn[i]>0) poz.push_back(val[i]);
            else neg.push_back(val[i]);
        }

        vector<ll> prefpoz;
        vector<ll> prefneg;
        partial_sum(poz.begin(),poz.end(),back_inserter(prefpoz));
        partial_sum(neg.begin(),neg.end(),back_inserter(prefneg));

        int ipoz=0;
        int ineg=0;

        for(int i:kandidati){
            while(ipoz<poz.size() && poz[ipoz]+i>=0) ipoz++;
            while(ineg<neg.size() && neg[ineg]-i<=0) ineg++;
            
            ll sum=0;

            sum-=(ipoz>0 ? prefpoz[ipoz-1]:0)+ipoz*i;
            sum+=(ipoz!=poz.size() ? range(ipoz,poz.size()-1,prefpoz):0)+(poz.size()-ipoz)*i;

            sum+=(ineg>0 ? prefneg[ineg-1]:0)+ineg*i;
            sum-=(ineg!=neg.size() ? range(ineg,neg.size()-1,prefneg):0)+(neg.size()-ineg)*i;

            best=min(best,{sum,i});
        }
        
        for(ll i:comp){
            res[i]=val[i]+best.second*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;
}

Compilation message

Graph.cpp: In function 'int main()':
Graph.cpp:89:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |             while(ipoz<poz.size() && poz[ipoz]+i>=0) ipoz++;
      |                   ~~~~^~~~~~~~~~~
Graph.cpp:90:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |             while(ineg<neg.size() && neg[ineg]-i<=0) ineg++;
      |                   ~~~~^~~~~~~~~~~
Graph.cpp:95:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |             sum+=(ipoz!=poz.size() ? range(ipoz,poz.size()-1,prefpoz):0)+(poz.size()-ipoz)*i;
      |                   ~~~~^~~~~~~~~~~~
Graph.cpp:98:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |             sum-=(ineg!=neg.size() ? range(ineg,neg.size()-1,prefneg):0)+(neg.size()-ineg)*i;
      |                   ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 2 ms 2656 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 3 ms 2656 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 1 ms 2644 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 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 1 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 2 ms 2656 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 3 ms 2656 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 1 ms 2644 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 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 1 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Incorrect 2 ms 2644 KB participant answer is larger than the answer of jury
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 2 ms 2656 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 3 ms 2656 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 1 ms 2644 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 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 1 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Incorrect 2 ms 2644 KB participant answer is larger than the answer of jury
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 2 ms 2656 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 3 ms 2656 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 1 ms 2644 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 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 1 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Incorrect 2 ms 2644 KB participant answer is larger than the answer of jury
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 2 ms 2656 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 3 ms 2656 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 1 ms 2644 KB answer = YES
12 Correct 1 ms 2644 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 2644 KB answer = YES
18 Correct 1 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 1 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Incorrect 2 ms 2644 KB participant answer is larger than the answer of jury
25 Halted 0 ms 0 KB -