Submission #1070341

#TimeUsernameProblemLanguageResultExecution timeMemory
1070341AdamGSTug of War (BOI15_tug)C++17
23 / 100
11 ms2908 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=3e4+7; vector<pair<int,int>>V[2*LIM]; int F[2*LIM], ile[2*LIM], n; int fnd(int x) { if(F[x]==x) return x; return F[x]=fnd(F[x]); } void uni(int a, int b) { a=fnd(a); b=fnd(b); if(a!=b) { ile[a]+=ile[b]; F[b]=a; } --ile[a]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int k; cin >> n >> k; rep(i, 2*n) { F[i]=i; ile[i]=1; } rep(i, 2*n) { int a, b, c; cin >> a >> b >> c; --a; --b; b+=n; V[a].pb({b, c}); V[b].pb({a, c}); uni(a, b); } rep(i, 2*n) if(ile[fnd(i)]<0) { cout << "NO\n"; return 0; } cout << "YES\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...