#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=2e5;
int n;
string s;
ar<int, 3> e[mxN];
set<ar<ll, 2>> seen;
vector<int> f[mxN];
int l[mxN];
multiset<int> seg;
set<ar<int, 2>> adj[mxN];
int tr;
void add(int i, int j, int c) {
adj[i].insert({j, c});
adj[j].insert({i, c});
}
set<ar<int, 2>>::iterator gt(int i, int j) {
auto it=adj[i].lower_bound({j});
assert(it!=adj[i].end()&&(*it)[0]==j);
return it;
}
void rem(int u) {
++tr;
int i=(*adj[u].begin())[0], j=(*adj[u].rbegin())[0];
int c1=(*adj[u].begin())[1], c2=(*adj[u].rbegin())[1];
adj[u].clear();
adj[i].erase(gt(i, u));
adj[j].erase(gt(j, u));
gt(i, j);
int c3=(*gt(j, i))[1];
if (c1==c2||c1==c3||c2==c3) {
cout << "neispravno bojenje";
exit(0);
}
if (adj[i].size()==2)
rem(i);
if (adj[j].size()==2)
rem(j);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> n >> s;
for (int i=0; i<n-3; ++i) {
cin >> e[i][0] >> e[i][1] >> e[i][2], --e[i][0], --e[i][1];
if (e[i][0]>e[i][1])
swap(e[i][0], e[i][1]);
if (seen.count({e[i][0], e[i][1]})) { // double edge??? bad..
cout << "neispravna triangulacija";
return 0;
}
seen.insert({e[i][0], e[i][1]});
f[e[i][0]].push_back(e[i][1]);
++l[e[i][1]];
}
for (int i=0; i<n; ++i) {
while(l[i]--) {
auto it=seg.find(i);
assert(it!=seg.end());
seg.erase(it);
}
assert(seg.empty()||*seg.begin()>i);
for (int j : f[i])
if (seg.size()&&j>*seg.begin()) {
cout << "neispravna triangulacija";
return 0;
}
for (int j : f[i])
seg.insert(j);
}
for (int i=0; i<n; ++i)
add(i, (i+1)%n, s[i]-'0');
for (int i=0; i<n-3; ++i)
add(e[i][0], e[i][1], e[i][2]);
for (int i=0; i<n; ++i)
if (adj[i].size()==2)
rem(i);
assert(tr==n-2);
cout << "tocno";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14412 KB |
Output is correct |
2 |
Correct |
8 ms |
14416 KB |
Output is correct |
3 |
Correct |
8 ms |
14340 KB |
Output is correct |
4 |
Correct |
8 ms |
14412 KB |
Output is correct |
5 |
Correct |
8 ms |
14336 KB |
Output is correct |
6 |
Correct |
8 ms |
14412 KB |
Output is correct |
7 |
Correct |
8 ms |
14412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14412 KB |
Output is correct |
2 |
Correct |
8 ms |
14416 KB |
Output is correct |
3 |
Correct |
8 ms |
14340 KB |
Output is correct |
4 |
Correct |
8 ms |
14412 KB |
Output is correct |
5 |
Correct |
8 ms |
14336 KB |
Output is correct |
6 |
Correct |
8 ms |
14412 KB |
Output is correct |
7 |
Correct |
8 ms |
14412 KB |
Output is correct |
8 |
Correct |
11 ms |
14948 KB |
Output is correct |
9 |
Correct |
11 ms |
14924 KB |
Output is correct |
10 |
Correct |
11 ms |
14540 KB |
Output is correct |
11 |
Correct |
9 ms |
14556 KB |
Output is correct |
12 |
Correct |
10 ms |
14924 KB |
Output is correct |
13 |
Correct |
11 ms |
14912 KB |
Output is correct |
14 |
Correct |
11 ms |
14944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
563 ms |
74096 KB |
Output is correct |
2 |
Correct |
558 ms |
74148 KB |
Output is correct |
3 |
Correct |
286 ms |
36560 KB |
Output is correct |
4 |
Correct |
302 ms |
36516 KB |
Output is correct |
5 |
Correct |
325 ms |
36528 KB |
Output is correct |
6 |
Correct |
681 ms |
95892 KB |
Output is correct |
7 |
Correct |
626 ms |
74252 KB |
Output is correct |
8 |
Correct |
261 ms |
36812 KB |
Output is correct |
9 |
Correct |
297 ms |
35612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
590 ms |
74100 KB |
Output is correct |
2 |
Correct |
574 ms |
74192 KB |
Output is correct |
3 |
Correct |
580 ms |
74320 KB |
Output is correct |
4 |
Correct |
580 ms |
74172 KB |
Output is correct |
5 |
Correct |
542 ms |
74192 KB |
Output is correct |
6 |
Correct |
628 ms |
87008 KB |
Output is correct |
7 |
Correct |
720 ms |
78844 KB |
Output is correct |
8 |
Correct |
687 ms |
76752 KB |
Output is correct |
9 |
Correct |
573 ms |
72132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14412 KB |
Output is correct |
2 |
Correct |
8 ms |
14416 KB |
Output is correct |
3 |
Correct |
8 ms |
14340 KB |
Output is correct |
4 |
Correct |
8 ms |
14412 KB |
Output is correct |
5 |
Correct |
8 ms |
14336 KB |
Output is correct |
6 |
Correct |
8 ms |
14412 KB |
Output is correct |
7 |
Correct |
8 ms |
14412 KB |
Output is correct |
8 |
Correct |
11 ms |
14948 KB |
Output is correct |
9 |
Correct |
11 ms |
14924 KB |
Output is correct |
10 |
Correct |
11 ms |
14540 KB |
Output is correct |
11 |
Correct |
9 ms |
14556 KB |
Output is correct |
12 |
Correct |
10 ms |
14924 KB |
Output is correct |
13 |
Correct |
11 ms |
14912 KB |
Output is correct |
14 |
Correct |
11 ms |
14944 KB |
Output is correct |
15 |
Correct |
563 ms |
74096 KB |
Output is correct |
16 |
Correct |
558 ms |
74148 KB |
Output is correct |
17 |
Correct |
286 ms |
36560 KB |
Output is correct |
18 |
Correct |
302 ms |
36516 KB |
Output is correct |
19 |
Correct |
325 ms |
36528 KB |
Output is correct |
20 |
Correct |
681 ms |
95892 KB |
Output is correct |
21 |
Correct |
626 ms |
74252 KB |
Output is correct |
22 |
Correct |
261 ms |
36812 KB |
Output is correct |
23 |
Correct |
297 ms |
35612 KB |
Output is correct |
24 |
Correct |
590 ms |
74100 KB |
Output is correct |
25 |
Correct |
574 ms |
74192 KB |
Output is correct |
26 |
Correct |
580 ms |
74320 KB |
Output is correct |
27 |
Correct |
580 ms |
74172 KB |
Output is correct |
28 |
Correct |
542 ms |
74192 KB |
Output is correct |
29 |
Correct |
628 ms |
87008 KB |
Output is correct |
30 |
Correct |
720 ms |
78844 KB |
Output is correct |
31 |
Correct |
687 ms |
76752 KB |
Output is correct |
32 |
Correct |
573 ms |
72132 KB |
Output is correct |
33 |
Correct |
577 ms |
74128 KB |
Output is correct |
34 |
Correct |
577 ms |
74184 KB |
Output is correct |
35 |
Correct |
332 ms |
36648 KB |
Output is correct |
36 |
Correct |
291 ms |
36580 KB |
Output is correct |
37 |
Correct |
562 ms |
74260 KB |
Output is correct |
38 |
Correct |
563 ms |
74264 KB |
Output is correct |
39 |
Correct |
544 ms |
74164 KB |
Output is correct |
40 |
Correct |
676 ms |
94672 KB |
Output is correct |
41 |
Correct |
703 ms |
80612 KB |
Output is correct |
42 |
Correct |
284 ms |
37784 KB |
Output is correct |
43 |
Correct |
630 ms |
76648 KB |
Output is correct |