답안 #855665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855665 2023-10-01T16:11:36 Z Trisanu_Das Graph (BOI20_graph) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
 
double EPS = 1e-8;
 
vector<pair<int, bool>> adj[100000];
int n, m, c[100000];
double x = 1e18, ans[100000];
bool s[100000], vis[100000], ok = true;
vector<int> comp;
 
void dfs(int u){
	vis[u] = 1; comp.push_back(u);
	for(auto &[v, w] : adj[u]){
		if(!vis[v]){
			s[v] = !s[u];
			c[v] = (2 - (int)w) - c[u];
			dfs(v);
		}else if(s[u] == s[v]) x = ((2 - (int)w) - c[u] - c[v]) / (s[u] ? -2.0 : 2.0);
	}
}
 
signed main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m;
	while(m--){
		int u, v, w; cin >> u >> v >> w;
		--u, --v;
		adj[u].emplace_back(v, w & 1);
		adj[v].emplace_back(u, w & 1);
	}
	for(int z = 0; z < n && ok; z++){
		if(vis[z]) continue;
		comp.clear(); x = 1e18; dfs(z);
		if(x > 1e17){
			vector<int> v;
			for(int i : comp) v.push_back(s[i] ? c[i] : -c[i]);
			sort(v.begin(), v.end());
			x = v[(int)v.size() / 2];
		}
		for(int i : comp) ans[i] = (c[i] + (s[i] ? -x : x));
	}
	for(int u = 0; u < n; u++) for(auto &[v, w] : adj[u]) ok &&= (abs((2 - (int)w) - ans[u] - ans[v]) < EPS);
	if(!ok) cout << "NO\n";
	else{
		cout << "YES\n";
		cout << setprecision(1) << fixed;
		for(int i = 0; i < n; i++) cout << ans[i] << ' ';
	}
}

Compilation message

Graph.cpp: In function 'int main()':
Graph.cpp:46:61: error: expected primary-expression before '=' token
   46 |  for(int u = 0; u < n; u++) for(auto &[v, w] : adj[u]) ok &&= (abs((2 - (int)w) - ans[u] - ans[v]) < EPS);
      |                                                             ^