10939 | 2024-04-20 17:23:01 | k_balint | Vasútépítés | cpp17 | Wrong answer 0/100 | 41ms | 8424 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';
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Wrong answer | 3ms | 1932 KiB | ||||
2 | Accepted | 3ms | 2248 KiB | ||||
3 | Wrong answer | 3ms | 2464 KiB | ||||
subtask2 | 0/40 | ||||||
4 | Wrong answer | 3ms | 2580 KiB | ||||
5 | Wrong answer | 3ms | 2828 KiB | ||||
6 | Wrong answer | 3ms | 2620 KiB | ||||
7 | Wrong answer | 3ms | 2624 KiB | ||||
8 | Wrong answer | 3ms | 2880 KiB | ||||
9 | Wrong answer | 3ms | 3164 KiB | ||||
10 | Wrong answer | 3ms | 3376 KiB | ||||
11 | Wrong answer | 3ms | 3548 KiB | ||||
subtask3 | 0/60 | ||||||
12 | Wrong answer | 3ms | 2580 KiB | ||||
13 | Wrong answer | 3ms | 2828 KiB | ||||
14 | Wrong answer | 3ms | 2620 KiB | ||||
15 | Wrong answer | 3ms | 2624 KiB | ||||
16 | Wrong answer | 3ms | 2880 KiB | ||||
17 | Wrong answer | 3ms | 3164 KiB | ||||
18 | Wrong answer | 3ms | 3376 KiB | ||||
19 | Wrong answer | 3ms | 3548 KiB | ||||
20 | Wrong answer | 3ms | 3804 KiB | ||||
21 | Wrong answer | 3ms | 3936 KiB | ||||
22 | Wrong answer | 3ms | 4108 KiB | ||||
23 | Wrong answer | 3ms | 4016 KiB | ||||
24 | Wrong answer | 3ms | 4160 KiB | ||||
25 | Wrong answer | 3ms | 4020 KiB | ||||
26 | Wrong answer | 3ms | 4052 KiB | ||||
27 | Wrong answer | 3ms | 4152 KiB | ||||
28 | Accepted | 41ms | 8424 KiB | ||||
29 | Accepted | 3ms | 4036 KiB | ||||
30 | Accepted | 3ms | 4032 KiB | ||||
31 | Accepted | 3ms | 4208 KiB |