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 <cstdio>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
const int maxn = 2e5 + 100;
inline int read(){
int x = 0;char c = getchar();
while(!isdigit(c))c = getchar();
while(isdigit(c))x = x * 10 + c - '0',c = getchar();
return x;
}
inline int readig(){
char c = getchar();
while(!isdigit(c))c = getchar();
return c - '0';
}
int n,flg;
map<int,int> col[maxn];
inline int bel(int x,int u){
if(x < u)return 1;
else return 2;
}
struct edge{
int u,v,c;
bool operator < (const edge &rhs)const{
if(bel(v,u) != bel(rhs.v,u))return bel(v,u) < bel(rhs.v,u);
return v > rhs.v;
}
};
vector<edge> G[maxn];
inline void addedge(int u,int v,int d){
G[u].push_back(edge{u,v,d});
}
inline int chk(int a,int b,int c){
return !((a == b) || (a == c) || (b == c));
}
int main(){
// freopen("checker.in","r",stdin);
// freopen("checker.out","w",stdout);
read();
n = read();
for(int c,i = 1;i < n;i++)c = col[i][i + 1] = col[i + 1][i] = readig(),addedge(i,i + 1,c),addedge(i + 1,i,c);
col[n][1] = col[1][n] = readig(); addedge(n,1,col[n][1]),addedge(1,n,col[1][n]);
for(int l,r,c,i = 1;i <= n - 3;i++){
l = read(),r = read(),c = read();
addedge(l,r,c);
addedge(r,l,c);
col[l][r] = col[r][l] = c;
}
for(int i = 1;i <= n;i++)sort(G[i].begin(),G[i].end());
for(int u = 1;u <= n;u++){
for(int i = 0;i < (int)G[u].size() - 1;i++){
int v1 = G[u][i].v,v2 = G[u][i + 1].v;
if(col[v1].find(v2) == col[v1].end())return puts("neispravna triangulacija"),0;
if(!chk(G[u][i].c,G[u][i + 1].c,col[v1][v2]))flg = 1;
}
}
if(flg)return puts("neispravno bojenje"),0;
puts("tocno");
fclose(stdin);
fclose(stdout);
return 0;
}
# | 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... |