QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#567930 | #9310. Permutation Counting 4 | EdGrass | WA | 0ms | 3532kb | C++23 | 959b | 2024-09-16 14:42:42 | 2024-09-16 14:42:43 |
Judging History
answer
#include<bits/stdc++.h>
using i64=long long;
void solve(){
std::set<int>st;
std::set<std::pair<int,int>>e;
int n; std::cin>>n;
std::vector<std::vector<int>>g(n+2);
std::vector<std::array<int,2>>a(n);
for(auto &[l,r]:a){
std::cin>>l>>r;
}
for(int i=0;i<n;i++){
auto [l,r]=a[i];
g[l].push_back(r+1);
if(e.count({l,r+1})){
std::cout<<"0\n";
return ;
}
e.insert({l,r+1});
st.insert(l);
st.insert(r+1);
}
if(!st.count(1)||st.size()!=e.size()+1){
std::cout<<"0\n";
return;
}
std::vector<int>fl(n+2,0);
auto dfs=[&](auto self,int u) -> void {
fl[u]=1;
for(auto v:g[u]){
if(fl[v])continue;
self(self,v);
}
};
dfs(dfs,1);
for(auto v:st){
if(!fl[v]){
std::cout<<0<<'\n';
return;
}
}
std::cout<<1<<'\n';
return;
}
signed main(){
std::cin.tie(0) -> sync_with_stdio(false);
int t=1; std::cin>>t;
while(t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3532kb
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:
0 0 0 0
result:
wrong answer 2nd words differ - expected: '1', found: '0'