답안 #258898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258898 2020-08-06T17:24:47 Z easrui Graph (BOI20_graph) C++14
0 / 100
3 ms 5120 KB
#include <bits/stdc++.h>
#define va first
#define vb second
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;

const int MN = 2e5+5;
const int MOD = 1e9+7;
const int INF = 1e9;

//start at 1:43

int E[MN],dep[MN],cnt[MN],par[MN],odd;
double C[MN],sum[MN],val[MN],tmp[MN];
vector<int> G[MN];
bool vis[MN],fail;

void dfs(int s)
{
	vis[s] = 1;
	for(int d:G[s]){
		if(odd) break;
		int e = E[d]-s;
		if(vis[e]){
			if(dep[e]<dep[s]) continue;
			if((dep[e]-dep[s])%2){
				if( (cnt[e]-cnt[par[s]]) - (cnt[par[e]]-cnt[s]) != C[d]-1) fail = 1;
			}
			else{
				odd = s;
				val[s] = (-sum[e]+sum[s]+sum[par[e]]-sum[par[s]]+C[d])/2.0;
			}
		}
		else{
			par[e] = s;
			dep[e] = dep[s]+1;
			cnt[e] = cnt[par[s]];
			if(C[d]==2) cnt[e]++;
			sum[e] = sum[par[s]]+C[d];
			dfs(e);
		}
	}
}

void solve(int s)
{
	vis[s] = 1;
	for(int d:G[s]){
		int e = E[d]-s;
		if(vis[e]){
			if(odd&&val[s]+val[e]!=C[d]) fail = 1;
		}
		else{
			val[e] = C[d]-val[s];
			tmp[e] = dep[e]%2 ? -val[e] : val[e];
			solve(e);
		}
	}
}

int N,M;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> N >> M;
    for(int i=0; i<M; i++){
    	int a,b;
    	cin >> a >> b >> C[i];
    	E[i] = a+b;
    	G[a].push_back(i);
    	G[b].push_back(i);
    }
    dfs(1);
    fill(vis,vis+N+1,0);

    if(odd) solve(odd);
    else{
    	solve(1);
	    sort(tmp+1,tmp+N+1);
	    double x = -tmp[(N+1)/2];
	    for(int i=1; i<=N; i++){
	    	if(dep[i]%2) val[i] -= x;
	    	else val[i] += x;
	    }
	}

    fixed(cout);
    cout.precision(6);
    if(fail) cout << "NO";
    else{
    	cout << "YES\n";
    	for(int i=1; i<=N; i++) cout << val[i] << ' ';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5120 KB answer = YES
2 Correct 3 ms 5120 KB answer = YES
3 Correct 3 ms 5120 KB answer = YES
4 Correct 3 ms 5120 KB answer = NO
5 Incorrect 3 ms 5120 KB Sum of endpoints for edge (5; 3) differs from the expected value 2.
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5120 KB answer = YES
2 Correct 3 ms 5120 KB answer = YES
3 Correct 3 ms 5120 KB answer = YES
4 Correct 3 ms 5120 KB answer = NO
5 Incorrect 3 ms 5120 KB Sum of endpoints for edge (5; 3) differs from the expected value 2.
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5120 KB answer = YES
2 Correct 3 ms 5120 KB answer = YES
3 Correct 3 ms 5120 KB answer = YES
4 Correct 3 ms 5120 KB answer = NO
5 Incorrect 3 ms 5120 KB Sum of endpoints for edge (5; 3) differs from the expected value 2.
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5120 KB answer = YES
2 Correct 3 ms 5120 KB answer = YES
3 Correct 3 ms 5120 KB answer = YES
4 Correct 3 ms 5120 KB answer = NO
5 Incorrect 3 ms 5120 KB Sum of endpoints for edge (5; 3) differs from the expected value 2.
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5120 KB answer = YES
2 Correct 3 ms 5120 KB answer = YES
3 Correct 3 ms 5120 KB answer = YES
4 Correct 3 ms 5120 KB answer = NO
5 Incorrect 3 ms 5120 KB Sum of endpoints for edge (5; 3) differs from the expected value 2.
6 Halted 0 ms 0 KB -