답안 #945428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945428 2024-03-13T19:05:00 Z LucaIlie Graph (BOI20_graph) C++17
0 / 100
1 ms 4724 KB
#include <bits/stdc++.h>

using namespace std;

struct edge {
    int u, v, c;

    int other( int x ) {
        return u ^ v ^ x;
    }
};

const int MAX_N = 1e5;
const int MAX_M = 2e5;
bool vis[MAX_N + 1];
int a[MAX_N + 1], b[MAX_N + 1];
double val[MAX_N + 1];
edge edges[MAX_M];
vector<int> adj[MAX_N + 1];

bool sePoate;
bool fixedX;
double x;
vector<int> vert;
void dfs( int u ) {
    vert.push_back( u );
    vis[u] = true;
    for ( int e: adj[u] ) {
        int v = edges[e].other( u ), c = edges[e].c;

        if ( !vis[v] ) {
            a[v] = -a[u];
            b[v] = c - b[u];
            dfs( v );
        } else {
            if ( a[u] + a[v] == 0 ) {
                if ( b[u] + b[v] != c )
                    sePoate = false;
            } else {
                double xx = ((double)c - b[u] - b[v]) / (a[u] + a[v]);
                if ( fixedX && x != xx )
                    sePoate = false;
                else {
                    fixedX = true;
                    x = xx;
                }
            }
        }
    }
}

int main() {
    int n, m;

    cin >> n >> m;
    for ( int i = 0; i < m; i++ ) {
        cin >> edges[i].u >> edges[i].v >> edges[i].c;
        adj[edges[i].u].push_back( i );
        adj[edges[i].v].push_back( i );
    }

    for ( int v = 1; v <= n; v++ ) {
        if ( vis[v] )
            continue;

        a[v] = 1;
        b[v] = 0;
        sePoate = true;
        fixedX = false;
        vert.clear();
        dfs( v );

        if ( !sePoate ) {
            cout << "NO\n";
            return 0;
        }
        
      	if ( !fixedX )
          x = 0;
        for ( int u: vert )
            val[u] = x * a[u] + b[u];
    }

    cout << "YES\n";
    for ( int v = 1; v <= n; v++ )
        cout << val[v] << " ";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB answer = YES
2 Correct 1 ms 4700 KB answer = YES
3 Correct 1 ms 4700 KB answer = YES
4 Correct 1 ms 4700 KB answer = NO
5 Correct 1 ms 4724 KB answer = YES
6 Incorrect 1 ms 4700 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB answer = YES
2 Correct 1 ms 4700 KB answer = YES
3 Correct 1 ms 4700 KB answer = YES
4 Correct 1 ms 4700 KB answer = NO
5 Correct 1 ms 4724 KB answer = YES
6 Incorrect 1 ms 4700 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB answer = YES
2 Correct 1 ms 4700 KB answer = YES
3 Correct 1 ms 4700 KB answer = YES
4 Correct 1 ms 4700 KB answer = NO
5 Correct 1 ms 4724 KB answer = YES
6 Incorrect 1 ms 4700 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB answer = YES
2 Correct 1 ms 4700 KB answer = YES
3 Correct 1 ms 4700 KB answer = YES
4 Correct 1 ms 4700 KB answer = NO
5 Correct 1 ms 4724 KB answer = YES
6 Incorrect 1 ms 4700 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB answer = YES
2 Correct 1 ms 4700 KB answer = YES
3 Correct 1 ms 4700 KB answer = YES
4 Correct 1 ms 4700 KB answer = NO
5 Correct 1 ms 4724 KB answer = YES
6 Incorrect 1 ms 4700 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -