답안 #395324

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395324 2021-04-28T08:12:45 Z ankhbayar06 자매 도시 (APIO20_swap) C++14
컴파일 오류
0 ms 0 KB
#include "swap.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define mk make_pair

int i,n,m,b[300000],t[300000],sz[300000],a[300000];
pair<int , pait<int , int>> p[300000];

void init(int N, int M, vector <int> U, vector <int> V, vector <int> W) {
    n = N;
    m = M;
    for (i=0 ; i<m ; i++){
        p[i].first=W[i];
        p[i].second.first=U[i];
        p[i].second.second=V[i];
    }
    sort (p,p+m);
}
int fnd(int xx){
	if(xx==t[xx]){
		return xx;
	}
	else t[xx]=fnd(t[xx]);
}
void negtge( int x , int y){
	x=fnd(x);
	y=fnd(y);
	if(sz[x] < sz[y]){
		swap(x,y);
	}
	sz[x]+=sz[y];
	if(b[y]==1){
		b[x]=1;
	}
	t[y]=x;
}
int getMinimumFuelCapacity(int u, int v){
	for(i=0 ; i<n ; i++){
		t[i]=i;
		sz[i]=1;
		b[i]=0;
		a[i]=0;
	}	
	for(i=0 ; i<m ; i++){
		x=p[i].second.first;
        y=p[i].second.second;	
        a[x]++;
        a[y]++;
        if(fnd(x)==fnd(y) || a[X]>2 || a[y]>2){
        	b[fnd(x)]=1;
        	b[fnd(y)]=1;
		}
		negtge(x,y);
		if(fnd(u)==fnd(v) && b[fnd(u)]==1){
			return p[i].first;
		}
	}
	
	return -1;	
}

Compilation message

swap.cpp:11:12: error: 'pait' was not declared in this scope
   11 | pair<int , pait<int , int>> p[300000];
      |            ^~~~
swap.cpp:11:26: error: template argument 2 is invalid
   11 | pair<int , pait<int , int>> p[300000];
      |                          ^~
swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:17:14: error: request for member 'first' in 'p[i]', which is of non-class type 'int'
   17 |         p[i].first=W[i];
      |              ^~~~~
swap.cpp:18:14: error: request for member 'second' in 'p[i]', which is of non-class type 'int'
   18 |         p[i].second.first=U[i];
      |              ^~~~~~
swap.cpp:19:14: error: request for member 'second' in 'p[i]', which is of non-class type 'int'
   19 |         p[i].second.second=V[i];
      |              ^~~~~~
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:49:3: error: 'x' was not declared in this scope
   49 |   x=p[i].second.first;
      |   ^
swap.cpp:49:10: error: request for member 'second' in 'p[i]', which is of non-class type 'int'
   49 |   x=p[i].second.first;
      |          ^~~~~~
swap.cpp:50:9: error: 'y' was not declared in this scope
   50 |         y=p[i].second.second;
      |         ^
swap.cpp:50:16: error: request for member 'second' in 'p[i]', which is of non-class type 'int'
   50 |         y=p[i].second.second;
      |                ^~~~~~
swap.cpp:53:32: error: 'X' was not declared in this scope
   53 |         if(fnd(x)==fnd(y) || a[X]>2 || a[y]>2){
      |                                ^
swap.cpp:59:16: error: request for member 'first' in 'p[i]', which is of non-class type 'int'
   59 |    return p[i].first;
      |                ^~~~~
swap.cpp: In function 'int fnd(int)':
swap.cpp:27:12: warning: control reaches end of non-void function [-Wreturn-type]
   27 |  else t[xx]=fnd(t[xx]);
      |       ~~~~~^~~~~~~~~~~