#include "bits/stdc++.h" using namespace std; #define dick vector #define full(a) a.begin(), a.end() using vi = vector; using vvi = vector; using pii = pair; #define V vector #define Vi V #define all(a) a.begin(), a.end() #define forn(i, n) for(int i=0; i> a(3); for(int i = 0; i<3; i++) { cin>>a[i].first>>a[i].second; } double mn = INT_MAX, mi = -1; for(int i = 0; i<3; i++) { pii other1 = a[(i+1) % 3]; pii other2= a[(i+2) % 3]; if(dist(other1.first - a[i].first, other2.second - a[i].second) < mn) { mn = dist(other1.first - a[i].first, other2.second - a[i].second); mi = i; } if(dist(other2.first - a[i].first, other1.second - a[i].second) < mn) { mn = dist(other2.first - a[i].first, other1.second - a[i].second); mi = i; } } cout<> a(3); for(int i = 0; i<3; i++) { cin>>a[i].first>>a[i].second; } double mn = INT_MAX, mi = -1; int precision = 10000; for(int i = -100 * precision; i <= 100*precision; i++) { for(int j = -100 * precision; i<= 100 * precision; i++) { double x = i*1.0/precision; double y = j*1.0/precision; for(int i = 0; i<3; i++) { pii other1 = a[(i+1) % 3]; pii other2= a[(i+2) % 3]; if(dotP(other1.first - x, other1.second - y, other2.first - x, other2.second - y) != 0) continue; if(dist2(x - a[i].first, y - a[i].second) < mn) { mn = dist2(x - a[i].first, y - a[i].second); mi = i; } } } } cout< middle(pair a, pair b) { return {(a.first + b.first) * 1.0 / 2, (a.second + b.second) * 1.0 / 2}; } pair minuss (pair a, pair b) { return {a.first - b.first, a.second - b.second}; } void solveA2() { vector> a(3); for(int i = 0; i<3; i++) { cin>>a[i].first>>a[i].second; } double mn = INT_MAX, mi = -1; for(int i = 0; i<3; i++) { pii other1 = a[(i+1) % 3]; pii other2 = a[(i+2) % 3]; pair mid = middle(other1, other2); pair alpha = minuss(a[i], mid); double r = sqrt((mid.first - other2.first) * (mid.first - other2.first) + (mid.second - other2.second) * (mid.second - other2.second)); double len = sqrt(alpha.first * alpha.first + alpha.second * alpha.second); pair alpha_n = {alpha.first / len, alpha.second / len}; pair alpha_n_times_r = {alpha_n.first * r, alpha_n.second * r}; pair the_point = {mid.first + alpha_n_times_r.first, mid.second + alpha_n_times_r.second}; double dst = dist(the_point.first - a[i].first, the_point.second - a[i].second); if(dst < mn) { mn = dst; mi = i; } // if(dist(other2.first - a[i].first, other1.second - a[i].second) < mn) { // mn = dist(other2.first - a[i].first, other1.second - a[i].second); // mi = i; // } } cout<>n>>q; dick a(n); for(int i =0 ;i < n ;i ++){ cin>>a[i]; } dick b(n); dick c(n); for(int i = 1;i < n ;i ++){ if( a[i] < a[i-1] )b[i] =-1; } for(int i = 1 ;i < n;i++){ c[i] = c[i- 1] + b[i]; } while(q--){ int r, l; cin>>r>> l; r--;l --; if(c[r] - c[l] != 0 ){ cout<< "NO\n"; } else cout<< "YES\n"; } return; } void solveS() { int n; cin >> n; array bs = {0}; forn(i, n) { int a; cin >> a; for(int j=0; a; j++, a/=2) { bs[j] += a&1; } } unsigned long long res = 0; for(int j=0; j<64; j++) { if(bs[j]) { res |= ((unsigned long long)1) << j; } bs[j+1] += bs[j] / 2; } cout << res; } void trains () { int n , m, t; cin>>n>>m>>t; for(int k =0 ;k < m ;k ++){ int p , s, l; string d; cin>>p>>s>>d>>l; int dist = t * s; int st, ed ; if(d == "R"){ st= p + dist; ed = st + l - 1; // if( st < ed)swap(st, ed); } else { st= p -dist; ed = st + l -1 ; } string res(n, '='); for(int i= 0 ;i < n ;i ++){ if(i == st ){ res[i] = '!'; } else if ( i >= min ( st, ed) && i <= max(st, ed)){ res[i] = '#'; } else res[i] = '='; } cout<< res << '\n'; } return ; } int xin() { int n; cin>>n; return n; } using vvpii=vector>>; #define pb push_back int timer = 0; using vb=vector; void dfs(int n, vvpii& g, int v, int c1, int c2, vi& used, int p = -1) { used[v] = ++timer; for(auto& to : g[v]) { if(to.first == p) continue; if(used[to.first] && used[to.first] < used[v]) { if(c1 + (to.second == 0) == c2 + (to.second == 1)) { continue; } if(c1 + (to.second == 0) >= 2 && c2 + (to.second == 1) >= 2) { continue; } cout<<"NO"< pdd get_per_point(int x1, int y1, int x2, int y2) { if(x1 == x2) { return {x1, y1+1}; } if(y1 == y2) return {x1+1, y1}; double k1 = (double)(y2 - y1) / (double)(x2 - x1); double k2 = -1/k1; double p2 = y1 - k2*x1; if(x1 != 0) { return {0, p2}; } return {1, k2*1 + p2}; } pdd to_vec(pdd a, pdd b) { return {b.F-a.F, b.S-a.S}; } double dot(pdd a, pdd b) { return a.F*b.F + a.S*b.S; } double norm_sq(pdd v) {return v.F*v.F + v.S*v.S;} double dist(pdd a, pdd b) { return sqrt((a.F-b.F)*(a.F-b.F) + (a.S-b.S)*(a.S*b.S)); } double dist_to_line(pdd p, pdd a, pdd b) { pdd ap = to_vec(a, p), ab=to_vec(a, b); double u = dot(ap, ab) / norm_sq(ab); a.F += ab.F * u; a.F += ab.S * u; return dist(p, a); } double solve(int x, int y, int x1, int y1, int x2, int y2) { auto [x3, y3] = get_per_point(x1, y1, x2, y2); cout << "p: " << x << ' ' << y << ", a1: " << x1 << ' ' << y1 << ", p2: " << x3 << ' ' << y3 <<'\n'; double dist = dist_to_line({x, y}, {x1, y1}, {x3, y3}); cout << "dist: " << dist <<'\n'; return dist; } void solveARoman() { int x1, x2, x3, y1, y2, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; double res = 1e9; res = min(res, solve(x1, y1, x2, y2, x3, y3)); res = min(res, solve(x1, y1, x3, y3, x2, y2)); res = min(res, solve(x2, y2, x1, y1, x3, y3)); res = min(res, solve(x2, y2, x3, y3, x1, y1)); res = min(res, solve(x3, y3, x1, y1, x2, y2)); res = min(res, solve(x3, y3, x2, y2, x1, y1)); cout << res << '\n'; } struct A {int idx, g_idx, val;}; V g; V> childs; V> ans; V tgt1, tgt2; void f2(int v) { for(auto [idx, g_idx, val] : childs[v]) { ans.push_back({v, g_idx, -val}); f2(g_idx); } childs[v].clear(); } int f1(int v, int p) { int val = 0; forn(i, g[v].size()) { int c = g[v][i]; if(c == p) continue; int c_val = f1(c, v); if(c_val == 0) continue; if(c_val > 0) { val += c_val; ans.push_back({c, v, c_val}); continue; } childs[v].push_back({i, c, c_val}); val += c_val; } val += tgt1[v] - tgt2[v]; if(val >= 0) { f2(v); return val; } return val; } void solveL() { ios::sync_with_stdio(false); int n; cin >> n; g.assign(n, {}); forn(i, n-1) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } int k; cin >> k; tgt1.assign(n, false); tgt2.assign(n, false); forn(i, k) { int j; cin >> j; tgt1[j] = true; } forn(i, k) { int j; cin >> j; tgt2[j] = true; } childs.assign(n, {}); int val = f1(0, -1); assert(val == 0); forn(i, n) assert(childs[i].empty()); cout << ans.size() << '\n'; for(auto [x, y, z] : ans) { assert(z >= 0); cout << x << ' ' << y << ' ' << z << '\n'; } }*/ //#define int long long struct UnionSet { #define DP_SIZE 300001 int dp[DP_SIZE]; int size[DP_SIZE]; void unite(int a, int b) { a = find(a); b = find(b); if (a != b) { if(size[a] < size[b]) swap(a, b); dp[b] = a; size[a] += size[b]; } } int find(int x) { if(dp[x] == x) return x; return dp[x] = find(dp[x]); } void init() { for(int i=0; i> n >> m; array>, 2> es; array uss = {}; uss[0].init(); uss[1].init(); forn(i, m) { int a, b, c; cin >> a >> b >> c; es[c].push_back({a, b}); uss[c].unite(a, b); } forn(c, 2) { for(auto [x, y] : es[c]) { if(uss[!c].find(x) == uss[!c].find(y)) { cout << "NO\n"; return; } } } cout << "YES\n"; } signed main() { solveN(); return 0; }