#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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2648 KB |
Output is correct |
2 |
Correct |
6 ms |
2652 KB |
Output is correct |
3 |
Correct |
6 ms |
2652 KB |
Output is correct |
4 |
Correct |
11 ms |
2880 KB |
Output is correct |
5 |
Correct |
5 ms |
2784 KB |
Output is correct |
6 |
Correct |
6 ms |
2908 KB |
Output is correct |
7 |
Correct |
6 ms |
2652 KB |
Output is correct |
8 |
Correct |
6 ms |
2908 KB |
Output is correct |
9 |
Correct |
5 ms |
2652 KB |
Output is correct |
10 |
Correct |
7 ms |
2908 KB |
Output is correct |
11 |
Correct |
5 ms |
2652 KB |
Output is correct |
12 |
Correct |
6 ms |
2908 KB |
Output is correct |
13 |
Correct |
6 ms |
2648 KB |
Output is correct |
14 |
Correct |
5 ms |
2652 KB |
Output is correct |
15 |
Correct |
7 ms |
2908 KB |
Output is correct |
16 |
Correct |
5 ms |
2864 KB |
Output is correct |
17 |
Correct |
8 ms |
2908 KB |
Output is correct |
18 |
Correct |
5 ms |
2652 KB |
Output is correct |
19 |
Correct |
8 ms |
2908 KB |
Output is correct |
20 |
Correct |
7 ms |
2652 KB |
Output is correct |
21 |
Correct |
6 ms |
2724 KB |
Output is correct |
22 |
Correct |
6 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |