#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pb push_back
using namespace std;
const int N=2e6,M=3e3+2,mod=1e9+7;
int seg[N],x[N],y[N],z[N];
vector< pair<int,int> > v[N];
vector<int>adj[N];
vector< pair<int,int> > adjj[N];
map< pair<int,int> , int > col;
void update(int v,int tl,int tr,int index){
if(tl==tr){
/*if(seg[v]==0)
seg2[v]=1;
else
seg3[v]=1;*/
seg[v]=!seg[v];
return ;
}
int tm=(tl+tr)/2;
if(index<=tm)
update(v*2,tl,tm,index);
else
update(v*2+1,tm+1,tr,index);
seg[v]=seg[v*2]+seg[v*2+1];
/*seg2[v]=seg2[v*2]+seg2[v*2+1];
seg3[v]=seg3[v*2]+seg3[v*2+1];*/
}
int get(int v,int tl,int tr,int l,int r){
if(tl>r||tr<l)
return 0;
if(tl>=l&&tr<=r)
return seg[v];
int tm=(tl+tr)/2;
return get(v*2,tl,tm,l,r)+get(v*2+1,tm+1,tr,l,r);
}
main(){
int xx;
cin>>xx;
if(xx==4||xx==3||xx==5){
int n;
cin>>n;
string s;
cin>>s;
for(int i=1;i<=n;i++){
if(i==n){
col[{n,1}]=s[i-1]-'0';
col[{1,n}]=s[i-1]-'0';
adj[1].pb(n);
adj[n].pb(1);
}
col[{i,i+1}]=s[i-1]-'0';
col[{i+1,i}]=s[i-1]-'0';
adj[i].pb(i+1);
adj[i+1].pb(i);
}
map<int,int>mp;
for(int i=0;i<n-3;i++){
cin>>x[i]>>y[i]>>z[i];
col[{x[i],y[i]}]=z[i];
col[{y[i],x[i]}]=z[i];
adj[x[i]].pb(y[i]);
adj[y[i]].pb(x[i]);
v[min(x[i],y[i])].pb({1,i+1});
v[max(x[i],y[i])].pb({0,i+1});
}
bool Final_ans=0;
for(int i=1;i<=n;i++){
for(auto x:v[i])
if(x.F==0)
update(1,1,n,mp[x.S]);
for(auto x:v[i]){
if(x.F==1)
continue;
int xxx=get(1,1,n,mp[x.S]+1,i);
if(xxx!=0)
Final_ans=1;
}
for(auto x:v[i]){
if(x.F==1)
mp[x.S]=i,update(1,1,n,i);
}
}
bool Final_ans2=0;
for(int i=0;i<n-3;i++){
if(adj[x[i]].size()<adj[y[i]].size()){
for(int j=0;j<adj[x[i]].size();j++){
if(col[{y[i],adj[x[i]][j]}]==0)
continue;
if(col[{y[i],adj[x[i]][j]}]==col[{x[i],adj[x[i]][j]}]||col[{y[i],adj[x[i]][j]}]==col[{y[i],x[i]}]||col[{x[i],adj[x[i]][j]}]==col[{x[i],y[i]}])
Final_ans2=1;
}
}
else{
for(int j=0;j<adj[y[i]].size();j++){
if(col[{x[i],adj[y[i]][j]}]==0)
continue;
if(col[{x[i],adj[y[i]][j]}]==col[{y[i],adj[y[i]][j]}]||col[{x[i],adj[y[i]][j]}]==col[{y[i],x[i]}]||col[{y[i],adj[y[i]][j]}]==col[{x[i],y[i]}])
Final_ans2=1;
}
}
}
if(Final_ans==1)
cout<<"neispravna triangulacija"<<endl;
else if(Final_ans==0&&Final_ans2==0)
cout<<"tocno"<<endl;
else if(Final_ans==0&&Final_ans2==1)
cout<<"neispravno bojenje"<<endl;
}
else{
int n;
cin>>n;
string s;
cin>>s;
map< pair<int,int> , pair<int,int> > mp;
for(int i=1;i<=n;i++){
if(i==n)
mp[{n,1}]={1,s[i-1]-'0'},mp[{1,n}]={1,s[i-1]-'0'};
mp[{i,i+1}]={1,s[i-1]-'0'};
mp[{i+1,i}]={1,s[i-1]-'0'};
}
for(int i=0;i<n-3;i++){
cin>>x[i]>>y[i]>>z[i];
adjj[x[i]].pb({y[i],z[i]});
adjj[y[i]].pb({x[i],z[i]});
mp[{x[i],y[i]}]={1,z[i]};
mp[{y[i],x[i]}]={1,z[i]};
}
int ok=0;
for(int i=0;i<n-3;i++){
for(int j=0;j<n-3;j++){
if(i==j)
continue;
if((min(x[i],y[i])<max(x[j],y[j]))&&(max(x[i],y[i])>max(x[j],y[j]))&&(min(x[i],y[i])>min(x[j],y[j])))
ok=1;
}
}
int ok2=0;
for(int i=0;i<n-3;i++){
for(int j=1;j<=n;j++){
if(j==x[i]||j==y[i])
continue;
pair<int,int> p;
p={0,0};
if((mp[{x[i],j}]. F!=0)&&(mp[{y[i],j}].F!=0)){
if((mp[{x[i],j}].S==mp[{y[i],j}].S)||(mp[{x[i],j}].S==mp[{x[i],y[i]}].S)||(mp[{y[i],j}].S==z[i]))
ok2=1;
}
}
}
if(ok2==0&&ok==0)
cout<<"tocno"<<endl;
else if(ok==0&&ok2==1)
cout<<"neispravno bojenje"<<endl;
else
cout<<"neispravna triangulacija"<<endl;
}
return 0;
}
Compilation message
checker.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
60 | main(){
| ^~~~
checker.cpp: In function 'int main()':
checker.cpp:141:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
141 | for(int j=0;j<adj[x[i]].size();j++){
| ~^~~~~~~~~~~~~~~~~
checker.cpp:155:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
155 | for(int j=0;j<adj[y[i]].size();j++){
| ~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
141576 KB |
Output is correct |
2 |
Correct |
69 ms |
141616 KB |
Output is correct |
3 |
Correct |
71 ms |
141572 KB |
Output is correct |
4 |
Correct |
65 ms |
141664 KB |
Output is correct |
5 |
Correct |
65 ms |
141688 KB |
Output is correct |
6 |
Correct |
66 ms |
141600 KB |
Output is correct |
7 |
Correct |
75 ms |
141608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
141576 KB |
Output is correct |
2 |
Correct |
69 ms |
141616 KB |
Output is correct |
3 |
Correct |
71 ms |
141572 KB |
Output is correct |
4 |
Correct |
65 ms |
141664 KB |
Output is correct |
5 |
Correct |
65 ms |
141688 KB |
Output is correct |
6 |
Correct |
66 ms |
141600 KB |
Output is correct |
7 |
Correct |
75 ms |
141608 KB |
Output is correct |
8 |
Correct |
613 ms |
314200 KB |
Output is correct |
9 |
Correct |
623 ms |
315732 KB |
Output is correct |
10 |
Correct |
624 ms |
315340 KB |
Output is correct |
11 |
Correct |
630 ms |
323960 KB |
Output is correct |
12 |
Correct |
624 ms |
316672 KB |
Output is correct |
13 |
Correct |
635 ms |
320128 KB |
Output is correct |
14 |
Correct |
620 ms |
316972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2236 ms |
257028 KB |
Output is correct |
2 |
Correct |
2179 ms |
256988 KB |
Output is correct |
3 |
Correct |
2075 ms |
257188 KB |
Output is correct |
4 |
Correct |
2187 ms |
257252 KB |
Output is correct |
5 |
Correct |
2191 ms |
257476 KB |
Output is correct |
6 |
Correct |
2179 ms |
239864 KB |
Output is correct |
7 |
Correct |
2063 ms |
236328 KB |
Output is correct |
8 |
Correct |
2078 ms |
238084 KB |
Output is correct |
9 |
Correct |
2059 ms |
237128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2173 ms |
257164 KB |
Output is correct |
2 |
Correct |
2164 ms |
257228 KB |
Output is correct |
3 |
Correct |
2169 ms |
257336 KB |
Output is correct |
4 |
Correct |
2143 ms |
256984 KB |
Output is correct |
5 |
Correct |
2078 ms |
257164 KB |
Output is correct |
6 |
Correct |
2132 ms |
238296 KB |
Output is correct |
7 |
Correct |
2023 ms |
236996 KB |
Output is correct |
8 |
Correct |
2089 ms |
239456 KB |
Output is correct |
9 |
Correct |
2029 ms |
236096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
141576 KB |
Output is correct |
2 |
Correct |
69 ms |
141616 KB |
Output is correct |
3 |
Correct |
71 ms |
141572 KB |
Output is correct |
4 |
Correct |
65 ms |
141664 KB |
Output is correct |
5 |
Correct |
65 ms |
141688 KB |
Output is correct |
6 |
Correct |
66 ms |
141600 KB |
Output is correct |
7 |
Correct |
75 ms |
141608 KB |
Output is correct |
8 |
Correct |
613 ms |
314200 KB |
Output is correct |
9 |
Correct |
623 ms |
315732 KB |
Output is correct |
10 |
Correct |
624 ms |
315340 KB |
Output is correct |
11 |
Correct |
630 ms |
323960 KB |
Output is correct |
12 |
Correct |
624 ms |
316672 KB |
Output is correct |
13 |
Correct |
635 ms |
320128 KB |
Output is correct |
14 |
Correct |
620 ms |
316972 KB |
Output is correct |
15 |
Correct |
2236 ms |
257028 KB |
Output is correct |
16 |
Correct |
2179 ms |
256988 KB |
Output is correct |
17 |
Correct |
2075 ms |
257188 KB |
Output is correct |
18 |
Correct |
2187 ms |
257252 KB |
Output is correct |
19 |
Correct |
2191 ms |
257476 KB |
Output is correct |
20 |
Correct |
2179 ms |
239864 KB |
Output is correct |
21 |
Correct |
2063 ms |
236328 KB |
Output is correct |
22 |
Correct |
2078 ms |
238084 KB |
Output is correct |
23 |
Correct |
2059 ms |
237128 KB |
Output is correct |
24 |
Correct |
2173 ms |
257164 KB |
Output is correct |
25 |
Correct |
2164 ms |
257228 KB |
Output is correct |
26 |
Correct |
2169 ms |
257336 KB |
Output is correct |
27 |
Correct |
2143 ms |
256984 KB |
Output is correct |
28 |
Correct |
2078 ms |
257164 KB |
Output is correct |
29 |
Correct |
2132 ms |
238296 KB |
Output is correct |
30 |
Correct |
2023 ms |
236996 KB |
Output is correct |
31 |
Correct |
2089 ms |
239456 KB |
Output is correct |
32 |
Correct |
2029 ms |
236096 KB |
Output is correct |
33 |
Correct |
2146 ms |
257084 KB |
Output is correct |
34 |
Correct |
2170 ms |
260056 KB |
Output is correct |
35 |
Correct |
2146 ms |
259916 KB |
Output is correct |
36 |
Correct |
2076 ms |
259968 KB |
Output is correct |
37 |
Correct |
2182 ms |
259952 KB |
Output is correct |
38 |
Correct |
2109 ms |
259820 KB |
Output is correct |
39 |
Correct |
2209 ms |
259928 KB |
Output is correct |
40 |
Correct |
2130 ms |
242520 KB |
Output is correct |
41 |
Correct |
2003 ms |
240068 KB |
Output is correct |
42 |
Correct |
1987 ms |
241192 KB |
Output is correct |
43 |
Correct |
2047 ms |
242176 KB |
Output is correct |