Submission #109316

# Submission time Handle Problem Language Result Execution time Memory
109316 2019-05-06T06:51:48 Z aer0park None (KOI17_civilization) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define f first
#define s second
 
using namespace std;
 
typedef int ll;
typedef pair<ll,ll> pi;
 
ll n,k,p[4000004],transp[2004][2004],cnt,coj,anw,vis[4000004];
bool ck[4000004];
ll dx[]={1,0,-1,0},dy[]={0,1,0,-1};
vector<pi> ar;
queue<pi> q;
 
ll par(int a)
{
    if(p[a]==a)
        return a;
    return p[a]=par(p[a]);
}
 
bool merge(ll a,ll b)    
{
    a=par(a),b=par(b);
    if(a!=b)
    {
        p[a]=b;
        return 1;   
    }
    return 0;
}
 
int main() 
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<k;i++)
    {
        ll a,b;scanf("%d%d",&a,&b);
        ar.emplace_back({a,b});
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            transp[i][j]=++cnt;
    for(int i=1;i<=n*n;i++)
        p[i]=i;
    memset(vis,-1,sizeof(vis));
    for(int i=0;i<k;i++)
    {
    	q.push(ar[i]);
    	vis[transp[ar[i].f][ar[i].s]]=0;
	}
    while(1)
    {
        while(!q.empty())
        {
            ll nwx=q.front().f,nwy=q.front().s;
            if(vis[transp[nwx][nwy]]!=anw)
            	break;
            q.pop();
            coj++;
            for(int i=0;i<4;i++)
            {
                ll ntx=nwx+dx[i],nty=nwy+dy[i];     
                if(ntx<1||ntx>n||nty<1||nty>n)
                    continue;
                if(vis[transp[ntx][nty]]==-1)
                	q.push({ntx,nty}),vis[transp[ntx][nty]]=anw+1;
				else if(vis[transp[ntx][nty]]<=anw)
                {
                    if(merge(transp[nwx][nwy],transp[ntx][nty]))
                		coj--;  
                }    	  
            }
        }
        if(coj==1)
        {
        	printf("%d",anw); 
            break;
        }
        anw++;
    }
    return 0;
}

Compilation message

civilization.cpp: In function 'int main()':
civilization.cpp:40:30: error: no matching function for call to 'std::vector<std::pair<int, int> >::emplace_back(<brace-enclosed initializer list>)'
         ar.emplace_back({a,b});
                              ^
In file included from /usr/include/c++/7/vector:69:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from civilization.cpp:1:
/usr/include/c++/7/bits/vector.tcc:95:7: note: candidate: void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {}; _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]
       vector<_Tp, _Alloc>::
       ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/7/bits/vector.tcc:95:7: note:   candidate expects 0 arguments, 1 provided
civilization.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~
civilization.cpp:39:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         ll a,b;scanf("%d%d",&a,&b);
                ~~~~~^~~~~~~~~~~~~~