답안 #233374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233374 2020-05-20T10:46:02 Z topovik Izlet (COI19_izlet) C++14
0 / 100
1816 ms 35880 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define f first
#define s second
#define pb push_back
#define INF 1000000000
#define N (long)1e5+2

using namespace std;

typedef long long ll;
typedef long double ld;

vector <vector <int> > gr;
vector <vector <int> > a1;

int n;
int pred[N];
int r[N];
int ans[N];
int a[3000][3000];

int Set(int x)
{
    if (pred[x]==x) return x;
    else            return pred[x]=Set(pred[x]);
}

void unite(int x, int y)
{
    if (r[x]>r[y]) pred[y]=x;
    else
    {
        pred[x]=y;
        if (r[x]==r[y]) r[y]++;
    }
}

void Check()
{
    bool mrk[n];
    for (int i=0; i<n; i++) mrk[i]=0;
    for (int i=0; i<n; i++)
        if (pred[i]==i) mrk[i]=1;
    for (int i=0; i<n; i++)
        for (int j=i+1; j<n; j++)
          if (i!=j && mrk[i] && mrk[j] && a[i][j]==2) a1[i].pb(j),a1[j].pb(i);

}

int main()
{
    cin>>n;
    cin>>n;
    gr.resize(n);
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++) cin>>a[i][j];
    int mx=0;
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++) mx=max(mx,a[i][j]);
    if (mx<3)
    {
    vector <pair<int,pair<int,int> > > qur;
    for (int i=0; i<n; i++)
        for (int j=i+1; j<n; j++)
    if (a[i][j]==1) qur.pb({a[i][j],{i,j}});
    for (int i=0; i<n; i++) pred[i]=i,r[i]=0;
    vector <pair<int,int> > ans;
    for (int i=0; i<qur.size(); i++)
        if (Set(qur[i].s.f)!=Set(qur[i].s.s))
    {
        int x=qur[i].s.f;
        int y=qur[i].s.s;
        ans.pb({x,y});
        unite(Set(x),Set(y));
    }
    int kol=0;
    int pr=-1;
    for (int i=0; i<n; i++)
    {
        cout<<(kol&1)+1<<" ";
        if (pred[i]==i)
        {
        kol++;
        if (pr!=-1) ans.pb({pr,i});
        pr=i;
        }
    }
    cout<<endl;
    for (int i=0; i<n-1; i++) cout<<ans[i].f+1<<" "<<ans[i].s+1<<endl;
    return 0;
    }
    int ans[n];
    int razl[n];
    for (int i=0; i<n; i++) razl[i]=0;
    ans[0]=1;
    razl[0]=1;
    int uniq=1;
    for (int i=1; i<n; i++)
    {
        bool g=1;
        for (int j=i-1; j>=0; j--)
            if (a[j][i]==razl[j]) {g=0;ans[i]=ans[j];break;}
        if (g) ans[i]=++uniq;
        for (int j=i; j>=0; j--)
        {
            if (a[j][i]==ans[i]) break;
            razl[j]++;
        }
    }
    for (int i=0; i<n; i++) cout<<ans[i]<<" ";
    cout<<endl;
    for (int i=0; i<n-1; i++) cout<<i+1<<" "<<i+2<<"\n";
}

Compilation message

izlet.cpp: In function 'int main()':
izlet.cpp:70:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<qur.size(); i++)
                   ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1816 ms 35880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -