QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#574006 | #9310. Permutation Counting 4 | DrGilbert | WA | 0ms | 11772kb | C++14 | 1.2kb | 2024-09-18 20:32:57 | 2024-09-18 20:32:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int L[N],R[N],deg[N],a[N],b[N];
vector<vector<int>> G;
void solve(){
int n,res=1;cin>>n;
G.clear();G.resize(n+10);
fill(deg,deg+1+n,0);
for (int i=1;i<=n;i++){
cin>>L[i]>>R[i];
G[L[i]].emplace_back(i);
if (R[i]<n) G[R[i]+1].emplace_back(i);
deg[i]+=1+(R[i]<n);
}queue<tuple<int,int,int>> que;
fill(a,a+1+n,0);fill(b,b+1+n,0);
for (int i=1;i<=n;i++){
if (deg[i]==1) que.emplace(i,L[i],1);
}while (que.size()){
auto [x,y,val]=que.front();que.pop();
if (a[x]||b[y]) return cout<<"tie\n",void();
a[x]=y,b[y]=x;res*=val;
for (int v:G[y]){
deg[v]--;
if (deg[v]==1){
if (y==L[v]) que.emplace(v,R[v]+1,-1);
else que.emplace(v,L[v],1);
}
}
}for (int i=1;i<=n;i++){
if (!a[i]||!b[i]) return cout<<"0\n",void();
}fill(b,b+1+n,0);int cnt=n;
for (int i=1;i<=n;i++){
if (b[i]) continue;
for (int x=i;!b[x];x=a[x]) b[x]=1;
cnt--;
}if (cnt&1) res*=-1;
if (res>0) cout<<"1\n";
else cout<<"1\n";
return;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(nullptr);cout.tie(nullptr);
int t;cin>>t;while (t--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 11772kb
input:
4 5 1 2 1 5 1 2 1 2 2 2 5 1 1 2 4 2 3 5 5 3 4 5 3 5 1 2 3 4 3 5 3 3 5 1 5 1 4 4 5 5 5 1 2
output:
tie 1 tie tie
result:
wrong answer 1st words differ - expected: '0', found: 'tie'