QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#79790#4892. 序列Larunatrecy0 25ms57996kbC++142.9kb2023-02-20 21:42:022023-02-20 21:42:06

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-20 21:42:06]
  • 评测
  • 测评结果:0
  • 用时:25ms
  • 内存:57996kb
  • [2023-02-20 21:42:02]
  • 提交

answer

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int N = 2e6+7;
int n,m;
struct edge
{
    int y,next;
}e[2*N];
int link[N],t=0;
void add(int x,int y)
{
    e[++t].y=y;
    e[t].next=link[x];
    link[x]=t;
}
vector<int> num[N];
int siz[N],tot=0;
inline int Big(int x,int i){return siz[x-1]+i+1;}
inline int Les(int x,int i){return siz[x-1]+i+1+tot;}
int A[N],B[N],C[N],D[N],cnt[N];
int dfn[N],low[N],tim=0;
int scc=0,col[N];
bool ins[N];
stack<int> stk;
void tarjan(int x)
{
    dfn[x]=low[x]=++tim;
    ins[x]=1;stk.push(x);
    for(int i=link[x];i;i=e[i].next)
    {
        int y=e[i].y;
        if(!dfn[y])
        {
            tarjan(y);
            low[x]=min(low[x],low[y]);
        }
        else if(ins[y])low[x]=min(low[x],dfn[y]);
    }
    if(dfn[x]==low[x])
    {
        ++scc;
        int y;
        do
        {
            y=stk.top();
            stk.pop();
            col[y]=scc;
            ins[y]=0;
        }while(x!=y);
    }
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int x,y,z,t;
        scanf("%d %d %d %d",&x,&y,&z,&t);
        num[x].push_back(t);
        num[y].push_back(t);
        num[z].push_back(t);
        A[i]=x;B[i]=y;C[i]=z;D[i]=t;
    }
    for(int i=1;i<=n;i++)
    {
        sort(num[i].begin(),num[i].end());
        unique(num[i].begin(),num[i].end())-num[i].begin();
        cnt[i]=num[i].size();
        siz[i]=siz[i-1]+cnt[i];
    }
    tot=siz[n];
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j+1<cnt[i];j++)
        {
            add(Les(i,j),Les(i,j+1));
            add(Big(i,j+1),Big(i,j));
        }
    }
    for(int i=1;i<=m;i++)
    {
        int x=A[i],y=B[i],z=C[i],t=D[i];
        int a=lower_bound(num[x].begin(),num[x].end(),t)-num[x].begin();
        int b=lower_bound(num[x].begin(),num[x].end(),t)-num[x].begin();
        int c=lower_bound(num[x].begin(),num[x].end(),t)-num[x].begin();
        add(Les(x,a),Big(y,b));add(Les(x,a),Big(z,c));
        add(Les(y,b),Big(x,a));add(Les(y,b),Big(z,c));
        add(Les(z,c),Big(x,a));add(Les(z,c),Big(y,b));
        if(a+1<cnt[x])a++;else a=-1;
        if(b+1<cnt[y])b++;else b=-1;
        if(c+1<cnt[z])c++;else c=-1;
        if(a!=-1&&b!=-1)add(Big(x,a),Les(y,b));if(a!=-1&&c!=-1)add(Big(x,a),Les(z,c));
        if(a!=-1&&b!=-1)add(Big(y,b),Les(x,a));if(b!=-1&&c!=-1)add(Big(y,b),Les(z,c));
        if(a!=-1&&c!=-1)add(Big(z,c),Les(x,a));if(b!=-1&&c!=-1)add(Big(z,c),Les(y,b));
    }
    for(int i=1;i<=2*tot;i++)if(!dfn[i])tarjan(i);
    for(int i=1;i<=n;i++)
    for(int j=0;j<cnt[i];j++)
    if(col[Big(i,j)]==col[Les(i,j)])
    {
        printf("NO\n");
        return 0;
    }
    printf("YES\n");
    for(int i=1;i<=n;i++)
    {
        int w=1;
        for(int j=0;j<cnt[i];j++)if(col[Big(i,j)]<col[Les(i,j)])w=num[i][j];
        printf("%d ",w);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 51036kb

input:

10 10
6 3 10 133562624
8 7 6 685486592
4 2 7 332482851
10 8 9 211550017
2 10 1 165556251
10 8 5 211550017
6 8 2 332482851
4 9 2 332482851
8 1 4 193658790
9 6 10 728674154

output:

NO

result:

wrong answer verdict is not correct

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 25ms
memory: 57996kb

input:

40 9880
4 19 31 610502845
10 19 33 190412843
21 24 39 649028784
16 22 40 569593239
5 9 37 550862419
11 23 40 654613112
6 18 23 492267246
22 23 30 538715841
6 16 24 407919735
5 16 18 388907784
2 16 18 388907784
21 24 28 281403057
7 12 27 451830401
3 11 16 508407438
15 33 36 561955959
6 23 29 70605893...

output:

NO

result:

wrong answer verdict is not correct

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #2:

0%