Submission #1101980

# Submission time Handle Problem Language Result Execution time Memory
1101980 2024-10-17T08:57:56 Z razivo Graph (BOI20_graph) C++14
5 / 100
1 ms 504 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Linear {
    double m,b;
    bool operator==(Linear a) const {
        return m==a.m && b==a.b;
    }
};
Linear Inv(Linear a) {
    return {a.m,-a.b*a.m};
}
Linear Compose(Linear a, Linear b) {
    return {a.m*b.m,b.b*a.m+a.b};
}
Linear Intersect(Linear a,Linear b) {
    return {0,-(a.b-b.b)/(a.m-b.m)};
}

Linear t1 = {-1,1};
Linear t2={-1,2};
Linear id={1,0};
vector<int> dsu;
vector<Linear> toParent;
vector<int> s;
void e() {
    cout<<"NO";
    exit(0);
}
pair<int,Linear> find(int a) {
    if(dsu[a]==a) return {a,id};
    auto [b,l] = find(dsu[a]);
    return {b,Compose(l,toParent[a])};
}
void un(int a,int b,Linear type) {
    auto [ap,la] = find(a);
    auto [bp,lb] = find(b);
    if(ap==bp) {
        if(Compose(type,Compose(la,toParent[ap]))==Compose(lb,toParent[bp])) {
            return;
        }else {
            if(!(toParent[ap]==id)) e();
            if(la.m!=lb.m) e();
            toParent[ap] = Intersect(Compose(type,la),lb);
        }
    }else {
        if(s[bp]<s[ap]) {
            swap(ap,bp);
            swap(la,lb);
        }
        if(toParent[ap]==id) {
            toParent[ap]=Compose(Inv(la),Compose(type,lb));
        }else {
            Linear atob = Compose(Inv(la),Compose(type,lb));
            if(toParent[bp]==id) {
                toParent[bp]=Compose(atob,toParent[ap]);
                toParent[ap]=atob;
            }else {
                if(Compose(atob,toParent[ap])==toParent[bp]) {
                    toParent[ap]=atob;
                }else {
                    e();
                }
            }
        }
        dsu[ap]=bp;
        s[bp]+=s[ap];
    }
}
void Solve(vector<pair<int,Linear>> &g,vector<double> &res) {
    sort(g.begin(), g.end(),[](pair<int,Linear> a,pair<int,Linear> b) {
        return b.second.b*b.second.m>a.second.b*a.second.m;
    });
    double t = -g[g.size()/2].second.b*g[g.size()/2].second.m;
    for(auto [a,l]:g) {
        res[a] = Compose(l,{0,t}).b;
    }
}
int main() {
    int n,m;cin>>n>>m;
    for (int i = 0; i < n; ++i) {
        dsu.push_back(i);
        toParent.push_back(id);
        s.push_back(1);
    }
    for (int i = 0; i < m; ++i) {
        int x,y,t; cin>>x>>y>>t; x--; y--;
        if(t==1) {
            un(x,y,t1);
        }else {
            un(x,y,t2);
        }
    }
    vector<vector<pair<int,Linear>>> g(n);
    vector<bool> type(n,true);
    for (int i = 0; i < n; ++i) {
        auto [a,l]=find(i);
        l= Compose(l,toParent[a]);
        if(l.m==0) type[a]=false;
        g[a].push_back({i,l});
    }
    vector<double> res(n);
    for (int i = 0; i < n; ++i) {
        if(g[i].size()==0) continue;
        if(type[i]) {
            Solve(g[i],res);
        }else {
            for(auto u : g[i]) {
                res[u.first]=u.second.b;
            }
        }
    }
    cout<<"YES"<<endl;
    for (int i = 0; i < n; ++i) {
        cout<<res[i]<<" ";
    }
}

Compilation message

Graph.cpp: In function 'std::pair<int, Linear> find(int)':
Graph.cpp:33:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |     auto [b,l] = find(dsu[a]);
      |          ^
Graph.cpp: In function 'void un(int, int, Linear)':
Graph.cpp:37:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |     auto [ap,la] = find(a);
      |          ^
Graph.cpp:38:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |     auto [bp,lb] = find(b);
      |          ^
Graph.cpp: In function 'void Solve(std::vector<std::pair<int, Linear> >&, std::vector<double>&)':
Graph.cpp:76:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   76 |     for(auto [a,l]:g) {
      |              ^
Graph.cpp: In function 'int main()':
Graph.cpp:98:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   98 |         auto [a,l]=find(i);
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB answer = YES
2 Correct 1 ms 336 KB answer = YES
3 Correct 1 ms 336 KB answer = YES
4 Correct 0 ms 336 KB answer = NO
5 Correct 1 ms 336 KB answer = YES
6 Correct 1 ms 336 KB answer = YES
7 Correct 0 ms 336 KB answer = YES
8 Correct 1 ms 336 KB answer = YES
9 Correct 0 ms 336 KB answer = NO
10 Correct 1 ms 336 KB answer = YES
11 Correct 1 ms 336 KB answer = YES
12 Correct 1 ms 336 KB answer = NO
13 Correct 1 ms 336 KB answer = YES
14 Correct 1 ms 336 KB answer = YES
15 Correct 0 ms 336 KB answer = YES
16 Correct 1 ms 504 KB answer = YES
17 Correct 1 ms 336 KB answer = YES
18 Correct 0 ms 336 KB answer = YES
19 Correct 1 ms 336 KB answer = YES
20 Correct 1 ms 336 KB answer = YES
21 Correct 1 ms 336 KB answer = YES
22 Correct 1 ms 504 KB answer = NO
23 Correct 1 ms 336 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB answer = YES
2 Correct 1 ms 336 KB answer = YES
3 Correct 1 ms 336 KB answer = YES
4 Correct 0 ms 336 KB answer = NO
5 Correct 1 ms 336 KB answer = YES
6 Correct 1 ms 336 KB answer = YES
7 Correct 0 ms 336 KB answer = YES
8 Correct 1 ms 336 KB answer = YES
9 Correct 0 ms 336 KB answer = NO
10 Correct 1 ms 336 KB answer = YES
11 Correct 1 ms 336 KB answer = YES
12 Correct 1 ms 336 KB answer = NO
13 Correct 1 ms 336 KB answer = YES
14 Correct 1 ms 336 KB answer = YES
15 Correct 0 ms 336 KB answer = YES
16 Correct 1 ms 504 KB answer = YES
17 Correct 1 ms 336 KB answer = YES
18 Correct 0 ms 336 KB answer = YES
19 Correct 1 ms 336 KB answer = YES
20 Correct 1 ms 336 KB answer = YES
21 Correct 1 ms 336 KB answer = YES
22 Correct 1 ms 504 KB answer = NO
23 Correct 1 ms 336 KB answer = NO
24 Correct 1 ms 336 KB answer = YES
25 Correct 1 ms 336 KB answer = YES
26 Correct 1 ms 336 KB answer = YES
27 Correct 1 ms 336 KB answer = YES
28 Correct 1 ms 336 KB answer = YES
29 Correct 1 ms 504 KB answer = YES
30 Correct 1 ms 504 KB answer = NO
31 Incorrect 1 ms 336 KB jury has the better answer: jans = YES, pans = NO
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB answer = YES
2 Correct 1 ms 336 KB answer = YES
3 Correct 1 ms 336 KB answer = YES
4 Correct 0 ms 336 KB answer = NO
5 Correct 1 ms 336 KB answer = YES
6 Correct 1 ms 336 KB answer = YES
7 Correct 0 ms 336 KB answer = YES
8 Correct 1 ms 336 KB answer = YES
9 Correct 0 ms 336 KB answer = NO
10 Correct 1 ms 336 KB answer = YES
11 Correct 1 ms 336 KB answer = YES
12 Correct 1 ms 336 KB answer = NO
13 Correct 1 ms 336 KB answer = YES
14 Correct 1 ms 336 KB answer = YES
15 Correct 0 ms 336 KB answer = YES
16 Correct 1 ms 504 KB answer = YES
17 Correct 1 ms 336 KB answer = YES
18 Correct 0 ms 336 KB answer = YES
19 Correct 1 ms 336 KB answer = YES
20 Correct 1 ms 336 KB answer = YES
21 Correct 1 ms 336 KB answer = YES
22 Correct 1 ms 504 KB answer = NO
23 Correct 1 ms 336 KB answer = NO
24 Correct 1 ms 336 KB answer = YES
25 Correct 1 ms 336 KB answer = YES
26 Correct 1 ms 336 KB answer = YES
27 Correct 1 ms 336 KB answer = YES
28 Correct 1 ms 336 KB answer = YES
29 Correct 1 ms 504 KB answer = YES
30 Correct 1 ms 504 KB answer = NO
31 Incorrect 1 ms 336 KB jury has the better answer: jans = YES, pans = NO
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB answer = YES
2 Correct 1 ms 336 KB answer = YES
3 Correct 1 ms 336 KB answer = YES
4 Correct 0 ms 336 KB answer = NO
5 Correct 1 ms 336 KB answer = YES
6 Correct 1 ms 336 KB answer = YES
7 Correct 0 ms 336 KB answer = YES
8 Correct 1 ms 336 KB answer = YES
9 Correct 0 ms 336 KB answer = NO
10 Correct 1 ms 336 KB answer = YES
11 Correct 1 ms 336 KB answer = YES
12 Correct 1 ms 336 KB answer = NO
13 Correct 1 ms 336 KB answer = YES
14 Correct 1 ms 336 KB answer = YES
15 Correct 0 ms 336 KB answer = YES
16 Correct 1 ms 504 KB answer = YES
17 Correct 1 ms 336 KB answer = YES
18 Correct 0 ms 336 KB answer = YES
19 Correct 1 ms 336 KB answer = YES
20 Correct 1 ms 336 KB answer = YES
21 Correct 1 ms 336 KB answer = YES
22 Correct 1 ms 504 KB answer = NO
23 Correct 1 ms 336 KB answer = NO
24 Correct 1 ms 336 KB answer = YES
25 Correct 1 ms 336 KB answer = YES
26 Correct 1 ms 336 KB answer = YES
27 Correct 1 ms 336 KB answer = YES
28 Correct 1 ms 336 KB answer = YES
29 Correct 1 ms 504 KB answer = YES
30 Correct 1 ms 504 KB answer = NO
31 Incorrect 1 ms 336 KB jury has the better answer: jans = YES, pans = NO
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB answer = YES
2 Correct 1 ms 336 KB answer = YES
3 Correct 1 ms 336 KB answer = YES
4 Correct 0 ms 336 KB answer = NO
5 Correct 1 ms 336 KB answer = YES
6 Correct 1 ms 336 KB answer = YES
7 Correct 0 ms 336 KB answer = YES
8 Correct 1 ms 336 KB answer = YES
9 Correct 0 ms 336 KB answer = NO
10 Correct 1 ms 336 KB answer = YES
11 Correct 1 ms 336 KB answer = YES
12 Correct 1 ms 336 KB answer = NO
13 Correct 1 ms 336 KB answer = YES
14 Correct 1 ms 336 KB answer = YES
15 Correct 0 ms 336 KB answer = YES
16 Correct 1 ms 504 KB answer = YES
17 Correct 1 ms 336 KB answer = YES
18 Correct 0 ms 336 KB answer = YES
19 Correct 1 ms 336 KB answer = YES
20 Correct 1 ms 336 KB answer = YES
21 Correct 1 ms 336 KB answer = YES
22 Correct 1 ms 504 KB answer = NO
23 Correct 1 ms 336 KB answer = NO
24 Correct 1 ms 336 KB answer = YES
25 Correct 1 ms 336 KB answer = YES
26 Correct 1 ms 336 KB answer = YES
27 Correct 1 ms 336 KB answer = YES
28 Correct 1 ms 336 KB answer = YES
29 Correct 1 ms 504 KB answer = YES
30 Correct 1 ms 504 KB answer = NO
31 Incorrect 1 ms 336 KB jury has the better answer: jans = YES, pans = NO
32 Halted 0 ms 0 KB -