QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#722675 | #6526. Canvas | HNO3il | WA | 3ms | 20596kb | C++14 | 1.8kb | 2024-11-07 19:53:26 | 2024-11-07 19:53:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
#define mp make_pair
int head[N],cnt,z[N],tp,dfn[N],low[N],ct,bl[N],tot,rd[N],vis[N];bool in[N],fl[N],as[N];
struct edge{int to,nxt;}e[N<<1];vector<pair<int,pair<int,int>>>q,g,w;
void add(int u,int v){e[++cnt]={v,head[u]},head[u]=cnt;}
void dfs(int u){dfn[u]=low[u]=++ct,z[++tp]=u,in[u]=1;
for(int i=head[u];i;i=e[i].nxt)
if(!dfn[e[i].to])dfs(e[i].to),low[u]=min(low[u],low[e[u].to]);
else if(in[e[i].to])low[u]=min(low[u],dfn[e[i].to]);
if(dfn[u]==low[u]){++tot;do bl[z[tp]]=tot,in[z[tp]]=1;while(z[tp--]!=u);}
}
int main(){int T;cin>>T;
while(T--){
memset(head,0,sizeof(head)),memset(vis,0,sizeof(vis)),memset(rd,0,sizeof(rd)),
memset(dfn,0,sizeof(dfn)),memset(fl,0,sizeof(fl)),memset(as,0,sizeof(as)),cnt=ct=0;q.clear(),g.clear(),w.clear();
int n,m,ans=0;cin>>n>>m;
for(int i=1,u,v,x,y;i<=m;i++){cin>>u>>x>>v>>y;if(!fl[u])ans+=2,fl[u]=1;if(!fl[v])ans+=2,fl[v]=1;
if(x==1&&y==2)add(u,v),w.push_back(mp(u,mp(v,i)));else if(x==2&&y==1)add(v,u),w.push_back(mp(v,mp(u,i)));
else if(x==2&&y==2)q.push_back(mp(u,mp(v,i)));else g.push_back(mp(u,mp(v,i)));
}
for(int i=1;i<=n;i++)if(!dfn[i])dfs(i);
for(pair<int,pair<int,int>>t:q)if(bl[t.first]==bl[t.second.first])vis[bl[t.first]]=t.second.second;
for(pair<int,pair<int,int>>t:w)if(bl[t.first]!=bl[t.second.first])++rd[bl[t.second.first]];
for(int i=1;i<=tot;i++)if(!rd[i]&&!vis[i]&&fl[i])--ans;
cout<<ans<<endl;vector<int>ass;
for(int i=1;i<=tot;i++)if(!rd[i]&&vis[i])ass.push_back(vis[i]),as[vis[i]]=1;
for(pair<int,pair<int,int>>t:q)if(!as[t.second.second])ass.push_back(t.second.second);
for(pair<int,pair<int,int>>t:w)ass.push_back(t.second.second);
for(pair<int,pair<int,int>>t:g)ass.push_back(t.second.second);
reverse(ass.begin(),ass.end());for(int i:ass)cout<<i<<' ';cout<<endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 19652kb
input:
2 4 4 1 1 2 2 3 2 4 1 1 2 3 2 2 1 4 1 4 2 3 2 4 1 1 2 3 1
output:
7 4 2 1 3 5 2 1
result:
ok Correct. (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 20596kb
input:
1 10 13 1 1 2 2 2 1 3 2 1 2 3 1 3 1 4 2 4 1 5 2 5 1 6 2 4 2 6 1 7 1 8 2 8 1 9 2 7 2 9 1 5 2 9 1 8 2 10 2 1 1 10 1
output:
18 13 11 10 9 8 7 6 5 4 3 2 1 12
result:
wrong answer Jury has better answer. Participant 18, jury 19 (test case 1)