답안 #257539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257539 2020-08-04T11:39:41 Z VEGAnn Graph (BOI20_graph) C++14
0 / 100
2 ms 2688 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define PB push_back
#define sz(x) ((int)x.size())
#define i2 array<int,2>
using namespace std;
typedef long double ld;
const int oo = 2e9;
const int N = 100100;
const int cnst = 100;
const int con = 50;
queue<int> q;
bool was;
vector<i2> g[N];
int n, m, col[N], mrk[N], tt;
int cost = 0, nm[N];

void BAD(){
    cout << "NO";
    exit(0);
}

mt19937 rnd(chrono::system_clock().now().time_since_epoch().count());

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m;

    for (int i = 0; i < m; i++){
        int x, y, z; cin >> x >> y >> z;
        x--; y--;

        g[x].PB({y, z * 2});
        g[y].PB({x, z * 2});
    }

    for (int i = 0; i < n; i++)
        nm[i] = i;

    fill(col, col + n, -oo);

//    shuffle(nm, nm + n, rnd);

    for (int ite = 0; ite < n; ite++){
//        int i = nm[ite];
        int i = ite;

        if (col[i] != -oo) continue;

        int best = oo, mem = -oo;

        for (int vl = -cnst; vl <= con; vl++){
            was = 0;

            tt++;

            cost = 0;

            while (sz(q)) q.pop();

            q.push(i);
            col[i] = vl;
            cost = abs(vl);
            mrk[i] = tt;

            while (!was && sz(q) && cost < best){
                int v = q.front(); q.pop();

                for (i2 u : g[v]){
                    if (mrk[u[0]] == tt){
                        if (col[u[0]] != u[1] - col[v]){
                            was = 1;
                            break;
                        }
                    } else {
                        q.push(u[0]);
                        mrk[u[0]] = tt;
                        col[u[0]] = u[1] - col[v];
                        cost += abs(col[u[0]]);
                    }
                }
            }

            if (!was && best > cost){
                best = cost;
                mem = vl;
            }
        }

        if (best == oo) BAD();

        tt++;

        while (sz(q)) q.pop();

        int vl = mem;

        q.push(i);
        col[i] = vl;
        mrk[i] = tt;

        while (sz(q)){
            int v = q.front(); q.pop();

            for (i2 u : g[v]){
                if (mrk[u[0]] == tt) {
                    q.push(u[0]);
                    mrk[u[0]] = tt;
                    col[u[0]] = u[1] - col[v];
                }
            }
        }
    }

    cout << "YES\n";

    for (int i = 0; i < n; i++)
        cout << fixed << setprecision(10) << ld(col[i]) / 2.0 << " ";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2688 KB Sum of endpoints for edge (1; 2) differs from the expected value 1.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2688 KB Sum of endpoints for edge (1; 2) differs from the expected value 1.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2688 KB Sum of endpoints for edge (1; 2) differs from the expected value 1.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2688 KB Sum of endpoints for edge (1; 2) differs from the expected value 1.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2688 KB Sum of endpoints for edge (1; 2) differs from the expected value 1.
2 Halted 0 ms 0 KB -