109352024-04-20 16:28:14k_balintVasútépítéscpp17Wrong answer 0/10090ms16136 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;
bool van;
int ans[c][c];
int par[c];

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){
    if(van) return;
    vis[v]=2;
    par[v]=p;

    for(int x:adj[v]){
        if(van) break;
        if(x==p) continue;
        if(vis[x]==1) dfs2(x,v);
        else if(!van){
            int k=v;
            while(k != par[x]){
                kor.push_back(k);
                k=par[k];
            }
            van=1;
        }
    }
}

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);
    }

    // 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;
    //         }
    //         kor.clear();
    //         van=0;
    //         dfs2(i,0);
    //         for(int j=0;j<kor.size();j++){
    //             int x=kor[(j+1)%kor.size()];
    //             int y=kor[j];
    //             ans[x][y]=ans[y][x]=++tt;
    //         }
    //     }
    // }

    for(int i=1;i<=n;i++){
        for(int x:adj[i]){
            if(!ans[x][i]){
                ans[x][i]=ans[i][x]=++tt;
            }
        }
    }

    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
1Accepted3ms2224 KiB
2Wrong answer3ms2400 KiB
3Wrong answer3ms3156 KiB
subtask20/40
4Wrong answer46ms10544 KiB
5Wrong answer46ms10724 KiB
6Wrong answer46ms10936 KiB
7Wrong answer46ms11144 KiB
8Wrong answer46ms11120 KiB
9Wrong answer46ms11132 KiB
10Wrong answer46ms11136 KiB
11Accepted3ms3172 KiB
subtask30/60
12Wrong answer46ms10544 KiB
13Wrong answer46ms10724 KiB
14Wrong answer46ms10936 KiB
15Wrong answer46ms11144 KiB
16Wrong answer46ms11120 KiB
17Wrong answer46ms11132 KiB
18Wrong answer46ms11136 KiB
19Accepted3ms3172 KiB
20Wrong answer46ms11152 KiB
21Wrong answer48ms11096 KiB
22Wrong answer46ms11364 KiB
23Wrong answer46ms11440 KiB
24Wrong answer46ms11336 KiB
25Wrong answer46ms11464 KiB
26Wrong answer46ms11560 KiB
27Wrong answer46ms11580 KiB
28Wrong answer90ms16136 KiB
29Wrong answer46ms11580 KiB
30Wrong answer46ms11592 KiB
31Wrong answer46ms11584 KiB