#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
vector<pair<int,int> > vec(n);
for(int i=0;i<n;i++) cin>>vec[i].first>>vec[i].second,vec[i].first--,vec[i].second--;
if(n&1){
cout<<"-1\n";
continue;
}
vector<int> prov(n),ans(n);
sort(vec.begin(),vec.end());
int left=0,right=0;
for(int i=0;i<n;i++){
if(s[vec[i].first]==s[vec[i].second]){
if(s[vec[i].first]=='(') prov[i]=1,left++;
else prov[i]=-1,right++;
}
}
if(left>n/2||right>n/2){
cout<<"-1\n";
continue;
}
int cnt=0;
for(int i=0;i<n;i++){
if(prov[i]==0){
if(cnt<n/2-left){
cnt++;
prov[i]=1;
}
else prov[i]=-1;
}
}
int now=0;
bool flag=1;
for(int i=0;i<n;i++){
if(prov[i]==1){
if(s[vec[i].first]=='(') ans[i]=0;
else ans[i]=1;
now++;
}
else{
if(s[vec[i].second]==')') ans[i]=1;
else ans[i]=0;
now--;
}
if(now<0){
flag=0;
break;
}
}
if(flag&&now==0){
for(auto x:ans) cout<<x<<" ";
cout<<"\n";
}
else cout<<"-1\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
14 ms |
1268 KB |
Output is correct |
3 |
Correct |
15 ms |
1836 KB |
Output is correct |
4 |
Correct |
13 ms |
1832 KB |
Output is correct |
5 |
Correct |
16 ms |
2212 KB |
Output is correct |
6 |
Correct |
16 ms |
2380 KB |
Output is correct |
7 |
Correct |
7 ms |
1884 KB |
Output is correct |
8 |
Correct |
12 ms |
2396 KB |
Output is correct |
9 |
Correct |
11 ms |
2788 KB |
Output is correct |
10 |
Correct |
17 ms |
3048 KB |
Output is correct |
11 |
Correct |
18 ms |
3548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |