109392024-04-20 17:23:01k_balintVasútépítéscpp17Wrong answer 0/10041ms8424 KiB
#include <bits/stdc++.h>
using namespace std;
const int c=1005;

int n,m,tt;
vector<int> adj[c];
int vis[c];
int cnt,deg;
vector<int> kor;
int ans[c][c];
int par[c];
bool korben[c];
int st,ed;

void dfs(int v){
    ++cnt; deg+=adj[v].size();
    vis[v]=1;
    for(int x:adj[v]){
        if(!vis[x]) dfs(x);
    }
}


void dfs2(int v, int p){
    par[v]=p;
    vis[v]=2;
    for(int x:adj[v]){
        if(x==p) continue;
        if(vis[x]==2){
            if(st==-1){
                st=x,ed=v;
            }
        }
        else dfs2(x,v);
    }
}

void dfs3(int v){
    vis[v]=1;
    for(int x:adj[v]){
        if(!korben[x] && !vis[x]){
            ans[v][x]=ans[x][v]=++tt;
            dfs3(x);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int a,b; cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    cout << -1 << endl;
    return 0;

    for(int i=1;i<=n;i++){
        if(!vis[i]){
            deg=0; cnt=0;
            dfs(i);
            if(deg>2*cnt){
                cout << -1 << endl;
                return 0;
            }
            st=-1,ed=-1;
            dfs2(i,0);
            if(st==-1) continue;
            ans[st][ed]=ans[ed][st]=++tt;

            korben[st]=1;
            int cur=ed;
            while(cur != st){
                korben[cur]=1;
                ans[cur][par[cur]]=ans[par[cur]][cur]=++tt;
                cur=par[cur];
            }
        }
    }

    for(int i=1;i<=n;i++) vis[i]=0;

    for(int i=1;i<=n;i++){
        if(!vis[i] && korben[i]) dfs3(i);
    }

    for(int i=1;i<=n;i++){
        if(!vis[i]) dfs3(i);
    }

    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            if(!ans[i][j]) ans[i][j]=++tt;
            cout << ans[i][j] << ' ';
        }
        cout << '\n';
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1932 KiB
2Accepted3ms2248 KiB
3Wrong answer3ms2464 KiB
subtask20/40
4Wrong answer3ms2580 KiB
5Wrong answer3ms2828 KiB
6Wrong answer3ms2620 KiB
7Wrong answer3ms2624 KiB
8Wrong answer3ms2880 KiB
9Wrong answer3ms3164 KiB
10Wrong answer3ms3376 KiB
11Wrong answer3ms3548 KiB
subtask30/60
12Wrong answer3ms2580 KiB
13Wrong answer3ms2828 KiB
14Wrong answer3ms2620 KiB
15Wrong answer3ms2624 KiB
16Wrong answer3ms2880 KiB
17Wrong answer3ms3164 KiB
18Wrong answer3ms3376 KiB
19Wrong answer3ms3548 KiB
20Wrong answer3ms3804 KiB
21Wrong answer3ms3936 KiB
22Wrong answer3ms4108 KiB
23Wrong answer3ms4016 KiB
24Wrong answer3ms4160 KiB
25Wrong answer3ms4020 KiB
26Wrong answer3ms4052 KiB
27Wrong answer3ms4152 KiB
28Accepted41ms8424 KiB
29Accepted3ms4036 KiB
30Accepted3ms4032 KiB
31Accepted3ms4208 KiB