QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#485202 | #8593. Coin | shenfe1 | 0 | 7ms | 31876kb | C++14 | 2.3kb | 2024-07-20 14:56:58 | 2024-07-20 14:56:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(a,i) memset(a,i,sizeof(a))
const int MAX=5e5+10;
int n,m;
vector<int> g[MAX],g1[MAX];
int use[MAX];
vector<int> top;
void dfs(int v){
use[v]=1;
for(auto to:g[v]){
if(!use[to])dfs(to);
}
top.pb(v);
}
void calc(int v){
use[v]=1;
for(auto to:g[v]){
if(use[to])continue;
calc(to);
}
}
bool ok[MAX];
bool solve(int i){
if(i==n-1){
ok[top[i]]=1;
return 1;
}
for(auto to:g[top[i]]){
if(to==top[i+1]){
ok[top[i]]=solve(i+1);
}
}
mem(use,0);
calc(top[i]);
int cnt=0;
for(int i=1;i<=n;i++)cnt+=use[i];
if(cnt==n-i){
ok[top[i]]=1;
return 1;
}
return 0;
}
bool ans[MAX];
void solve(){
cin>>n>>m;
for(int i=1;i<=m;i++){
int a,b;
cin>>a>>b;
g[a].pb(b);
g1[b].pb(a);
}
{
mem(use,0);
for(int i=1;i<=n;i++){
if(!use[i]){
dfs(i);
}
}
mem(use,0);
reverse(all(top));
calc(top[0]);
int cnt=0;
for(int i=1;i<=n;i++){
cnt+=use[i];
}
// cout<<cnt<<"\n";
if(cnt==n){
solve(0);
}
}
for(int i=1;i<=n;i++){
// cout<<top[i-1]<<" "<<ok[i]<<"\n";
ans[i]=ok[i];
ok[i]=0;
swap(g[i],g1[i]);
}
top.clear();
{
mem(use,0);
for(int i=1;i<=n;i++){
if(!use[i]){
dfs(i);
}
}
mem(use,0);
reverse(all(top));
calc(top[0]);
int cnt=0;
for(int i=1;i<=n;i++){
cnt+=use[i];
}
if(cnt==n){
solve(0);
}
}
for(int i=1;i<=n;i++){
if(ans[i]||ok[i])cout<<1<<" ";
else cout<<-1<<" ";
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--)solve();
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Acceptable Answer
time: 0ms
memory: 31876kb
input:
4 4 2 4 3 1 4 1 2 3
output:
1 1 -1 -1
result:
points 0.50 -1 correct
Test #2:
score: 3
Acceptable Answer
time: 3ms
memory: 31020kb
input:
6 8 1 5 5 4 6 2 2 5 4 3 6 1 6 5 2 1
output:
1 1 1 1 1 1
result:
points 0.50 -1 correct
Test #3:
score: 6
Accepted
time: 3ms
memory: 31028kb
input:
2 1 1 2
output:
1 1
result:
ok ac
Test #4:
score: 3
Acceptable Answer
time: 7ms
memory: 30968kb
input:
6 12 1 5 5 4 6 2 2 5 4 3 6 5 1 5 1 5 2 4 6 3 1 3 4 3
output:
-1 -1 1 1 1 -1
result:
points 0.50 -1 correct
Test #5:
score: 3
Acceptable Answer
time: 7ms
memory: 31132kb
input:
7 20 1 6 6 3 1 4 1 5 1 7 1 2 1 5 2 3 4 5 7 2 2 4 5 3 6 3 1 3 4 3 7 5 2 6 4 6 7 2 7 5
output:
1 1 1 1 -1 -1 1
result:
points 0.50 -1 correct
Test #6:
score: 0
Wrong Answer
time: 3ms
memory: 31020kb
input:
7 20 5 6 1 3 3 6 4 1 7 4 2 5 4 3 2 6 7 5 4 6 2 6 2 1 4 5 1 3 1 5 7 1 7 6 4 1 7 6 3 6
output:
-1 -1 -1 -1 -1 1 -1
result:
wrong answer wa
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%