답안 #1074235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1074235 2024-08-25T08:58:22 Z Trumling 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std; 

typedef long long ll;
#define pb push_back
#define F first
#define S second
#define enter cout<<'\n';
#define INF 99999999999999999
#define MOD 1000000007
#define all(x) x.begin(),x.end()

vector<vector<pair<ll,ll>>>g;
vector<bool>vis;
ll n,m;
void dfs1(int start,ll &count)
{
    for(auto x:g[start])
        if(!vis[x.F])
        {
            vis[x.F]=1;
            count+=x.S;
            dfs1(x.F, count);
        }
}

void dfs2(int start,int pre,ll &ans,ll diff,ll curr,ll count)
{
    if(diff > abs((count-curr)-curr))
            {
                ans=max(curr,count-curr);
                diff= abs((count-curr)-curr);
            }

    for(auto x:g[start])
        if(x.F!=pre)
            dfs2(x.F,start,ans,diff,curr + x.S,count);
        
}   
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n=N;
    m=M;

    g.assign(n,vector<pair<ll,ll>>());
    vis.assign(n,0);

    for(int i=0;i<m;i++)
        {
            g[A[i]].pb({B[i],T[i]});
            g[B[i]].pb({A[i],T[i]});
        }
    
    vector<ll>ans(2,0);
    ll ansi=0;
    ll idx=0;
    for(int i=0;i<N;i++)
        if(!vis[i] && g[i].size()==1)
        {
            vis[i]=1;
            ll count=0;
            dfs1(i,count);
            ansi=max(ansi,count);

            dfs2(i,i,ans[idx++],INF,0,count);
        }
    


    return max(ansi,ans[0] + ans[1] + L);

}

#include <stdio.h>
#include <stdlib.h>
#include "dreaming.h"

#define fail(s, x...) do { \
		fprintf(stderr, s "\n", ## x); \
		exit(1); \
	} while(0)

#define MAX_N 100000

static int A[MAX_N];
static int B[MAX_N];
static int T[MAX_N];

int main() {
	int N, M, L, i;
	int res;

	

	cin>>N>>M>>L;
	for (i = 0; i < M; i++)
		cin>>A[i]>>B[i]>>T[i];

	int answer = travelTime(N, M, L, A, B, T);
	printf("%d\n", answer);

	return 0;
}

Compilation message

dreaming.cpp: In function 'int main()':
dreaming.cpp:91:6: warning: unused variable 'res' [-Wunused-variable]
   91 |  int res;
      |      ^~~
/usr/bin/ld: /tmp/ccflMq0u.o: in function `main':
dreaming.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccaqoANt.o:grader.c:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status