이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x).size()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int MX_N = 2e5+5;
using ii = pair<int,int>;
int ST;
int N;
int deg[MX_N];
set<ii> hull;
map<ii,int> edges;
queue<set<ii>::iterator> q;
bool check(set<ii>::iterator it) {
if (deg[it->first] != 2) return false;
//cout << "CHECKING " << it->first << " " << it->second << endl;
auto prv = (it == hull.begin() ? prev(hull.end()) : prev(it));
auto nxt = (next(it) == hull.end() ? hull.begin() : next(it));
ii e = ii(prv->first, nxt->first);
//cout << "\t edge " << e.first << " " << e.second << endl;
if (e.first > e.second) swap(e.first, e.second);
//cout << "\t good? " << edges.count(e) << endl;
return edges.count(e);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> ST;
cin >> N;
FOR(i,1,N){
char C; cin >> C;
edges[ii(i,i+1)] = C;
hull.insert(ii(i,C-'0'));
deg[i] = 2;
}
FOR(i,1,N-3){
int X, Y, C; cin >> X >> Y >> C;
if (X > Y) swap(X,Y);
edges[ii(X,Y)] = C;
++deg[X];
++deg[Y];
}
//set<ii>::iterator P = hull.end();
for (auto it = hull.begin(); it != hull.end(); ++it) {
//cout << "TRY " << it->first << " " << it->second << endl;
if (check(it)) {
//P = it;
q.push(it);
}
}
bool isPat = true;
while (!q.empty() && SZ(hull) > 2) {
auto P = q.front(); q.pop();
auto prv = (P == hull.begin() ? prev(hull.end()) : prev(P));
auto nxt = (next(P) == hull.end() ? hull.begin() : next(P));
ii e = ii(prv->first, nxt->first);
if (e.first > e.second) swap(e.first, e.second);
//cout << "HULL IS NOW " << SZ(hull) << " :: P " << P->first << " " << P->second << " :: E " << e.first << " " << e.second << endl;
int a = prv->second, b = P->second, c = edges[e];
isPat &= (a != b && a != c && b != c);
hull.erase(P);
--deg[e.first];
--deg[e.second];
ii nw = ii(prv->first, c);
hull.erase(prv);
hull.insert(nw);
//for (auto& x : hull) cout << x.first << " " << x.second << " || ";
//cout << endl;
if (check(nxt)) q.push(nxt);
if (check(prev(nxt))) q.push(prev(nxt));
}
if (SZ(hull) != 2) {
cout << "neispravna triangulacija" << '\n';
} else if (!isPat) {
cout << "neispravno bojenje" << '\n';
} else {
cout << "tocno" << '\n';
}
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |