답안 #855659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855659 2023-10-01T16:05:32 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, r[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] : g[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;
		g[u].emplace_back(v, w & 1);
		g[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) r[i] = (c[i] + (s[i] ? -x : x));
	}
	for(int u = 0; u < n; u++) for(auto &[v, w] : g[u]) ok &&= abs((2 - (int)w) - r[u] - r[v]) < EPS;
	if(!ok) cout << "NO\n";
	else{
		cout << "YES\n";
		cout << setprecision(1) << fixed;
		for(int i = 0; i < n; i++) cout << r[i] << ' ';
	}
}

Compilation message

Graph.cpp: In function 'void dfs(long long int)':
Graph.cpp:17:21: error: 'g' was not declared in this scope
   17 |  for(auto &[v, w] : g[u]){
      |                     ^
Graph.cpp: In function 'int main()':
Graph.cpp:32:3: error: 'g' was not declared in this scope
   32 |   g[u].emplace_back(v, w & 1);
      |   ^
Graph.cpp:46:48: error: 'g' was not declared in this scope
   46 |  for(int u = 0; u < n; u++) for(auto &[v, w] : g[u]) ok &&= abs((2 - (int)w) - r[u] - r[v]) < EPS;
      |                                                ^
Graph.cpp:46:59: error: expected primary-expression before '=' token
   46 |  for(int u = 0; u < n; u++) for(auto &[v, w] : g[u]) ok &&= abs((2 - (int)w) - r[u] - r[v]) < EPS;
      |                                                           ^