# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
146136 | evpipis | Tug of War (BOI15_tug) | C++11 | 15 ms | 2684 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef pair<int, int> ii;
const int len = 6e4+4;
int vis[len];
vector<ii> adj[len];
int check(int u){
vis[u] = 1;
int ans = 2-adj[u].size();
for (int j = 0; j < adj[u].size(); j++){
ii v = adj[u][j];
if (!vis[v.fi])
ans += check(v.fi);
}
return ans;
}
int main(){
int n, k;
scanf("%d %d", &n, &k);
for (int i = 0; i < 2*n; i++){
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
adj[2*a-2].pb(mp(2*b-1, c));
adj[2*b-1].pb(mp(2*a-2, c));
}
for (int i = 1; i <= n; i++)
if (!vis[2*i-2] && check(2*i-2) != 0){
printf("NO\n");
return 0;
}
printf("YES\n");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |