Submission #1078848

#TimeUsernameProblemLanguageResultExecution timeMemory
1078848Rawlat_vanakCyberland (APIO23_cyberland)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define speedIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define mod 1000000007 #define f first #define s second #define pii pair<int,int> #define pb push_back vector<vector<pii>> graph; vector<int> parent,sz; int find(int u){ while(u!=parent[u]) u=parent[u]; return parent[u]; } void unite(int a,int b){ a=find(a);b=find(b); if(a==b) return; if(sz[b]>sz[a]) swap(a,b); parent[b]=a; sz[a]+=sz[b]; } double solve(int n,int m,int k,int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){ parent.resize(n); for(int i=0;i<n;i++){ parent[i]=i; } sz.resize(n,1); graph.resize(n); for(int i=0;i<n;i++){ graph[x[i]].pb({y[i],c[i]}); graph[y[i]].pb({x[i],c[i]}); unite(x[i],y[i]); } priority_queue<pii> q; vector<vector<double>> dist(n,vector<double>(k+1,1e15)); vector<bool> visited(n,false); for(int j=0;j<=k;j++){ if(find(0)==find(h)){ dist[0][j]=0; q.push({0,0}); } visited[0]=false; for(int i=1;i<n;i++){ visited[i]=false; if(arr[i]==0 and find(i)==find(h)){ dist[i][j]=0; q.push({0,i}); } } while(!q.empty()){ pii u=q.top(); int v=u.s; q.pop(); if(visited[v]) continue; visited[v]=true; for(pii w: graph[v]){ int x=w.f,c=w.s; if(arr[x]==1){ if(dist[w.f][j]>dist[v][j]+w.s){ dist[w.f][j]=dist[v][j]+w.s; q.push({-dist[w.f][j],w.f}); } }else if(arr[x]==2){ if(dist[w.f][j]>dist[v][j]+w.s){ dist[w.f][j]=dist[v][j]+w.s; q.push({-dist[w.f][j],w.f}); } if(j>=1){ if(dist[x][j]>(dist[v][j-1]+c)/2){ dist[x][j]=(dist[v][j-1]+c)/2; q.push({-dist[x][j],x}); } } } } } } double ans=1e15; for(int i=0;i<=k;i++){ ans=min(ans,dist[h][i]); } for(int i=0;i<n;i++){ graph[i].clear(); dist[i].clear(); parent.clear(); visited.clear(); sz.clear(); } if(ans==1e15){ return -1; }else{ return ans; } } int32_t main(){ speedIO; int t,n,m,q,k,h; cin>>t; //t=1; while(t--){ //string s; cin>>n>>m>>k>>h; vector<int> x(n),y(n),c(n),arr(n); for(int i=0;i<m;i++){ cin>>x[i]>>y[i]>>c[i]; } for(int i=0;i<n;i++){ cin>>arr[i]; } cout<<solve(n,m,k,h,x,y,c,arr); } //} return 0; }

Compilation message (stderr)

cyberland.cpp: In function 'int32_t main()':
cyberland.cpp:109:12: warning: unused variable 'q' [-Wunused-variable]
  109 |  int t,n,m,q,k,h;
      |            ^
/usr/bin/ld: /tmp/ccLbECVs.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccXGoS5u.o:cyberland.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccLbECVs.o: in function `main':
grader.cpp:(.text.startup+0x696): undefined reference to `solve(int, int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status