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;
int const N = 2e5 + 5;
vector<pair<int, int> > have[N];
int instk[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, t;
cin >> t;
cin >> n;
string s;
cin >> s;
int u, v, c;
for(int i = 0; i < n - 3; i++){
cin >> u >> v >> c;
if(u > v)
swap(u, v);
have[u].push_back({v, c});
}
vector<int> stk;
for(int i = 1; i <= n; i++){
while(instk[i]){
if(stk.back() != i){
cout << "neispravna triangulacija\n";
return 0;
}else{
stk.pop_back();
instk[i]--;
}
}
sort(have[i].begin(), have[i].end());
for(int j = (int)have[i].size() - 1; j >= 0; j--){
stk.push_back(have[i][j].first);
instk[have[i][j].first]++;
}
}
vector<pair<int,int> > st;
vector<int> stk2;
for(int i = 1; i <= n; i++){
while(instk[i]){
if(st.back().second == stk2.back() || stk2.back() == stk2[stk2.size() - 2] || stk2[stk2.size() - 2] == st.back().second){
cout << "neispravno bojenje\n";
return 0;
}
stk2.pop_back();
stk2.pop_back();
stk2.push_back(st.back().second);
st.pop_back();
instk[i]--;
}
for(int j = (int)have[i].size() - 1; j >= 0; j--){
st.push_back(have[i][j]);
instk[have[i][j].first]++;
}
if(i == n){
if(s[i - 1] - '0' == stk2.back() || stk2.back() == stk2[stk2.size() - 2] || stk2[stk2.size() - 2] == s[i - 1] - '0'){
cout << "neispravno bojenje\n";
return 0;
}
}
stk2.push_back(s[i - 1] - '0');
}
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... |