제출 #778016

#제출 시각아이디문제언어결과실행 시간메모리
778016Cookie꿈 (IOI13_dreaming)C++14
100 / 100
68 ms15348 KiB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#include <stdio.h>
#include <stdlib.h>
const ll inf = 1e9 + 6;
#include "dreaming.h"
const int mxn = 1e5 + 5;
vt<pii>adj[mxn + 1];
int n;
bool vis[mxn + 1];
int to[mxn + 1];
vt<int>comp;
vt<int>bfs(int s){
    // bfs works since it is a tree
    vt<int>dis(sz(comp), -1);
    queue<int>q; q.push(s); dis[s] = 0;
    while(!q.empty()){
        int nw = q.front(); q.pop();
        for(auto [v, w]: adj[comp[nw]]){
            if(dis[to[v]] == -1){
                dis[to[v]] = dis[nw] + w;
                q.push(to[v]);
            }
        }
    }
    return(dis);
}
void dfs(int s){
    vis[s] = 1; comp.pb(s);
    for(auto [v, w]: adj[s]){
        if(!vis[v]){
            dfs(v); 
        }
    }
}
int travelTime(int N, int m, int L, int A[], int B[], int T[]) {
    n = N;
    forr(i, 0, m){
        int u = A[i], v = B[i], w = T[i];
        adj[u].pb({v, w}); adj[v].pb({u, w});
    }
    int ans = 0, diam = 0;
    vt<int>cand;
    forr(i, 0, n){
        if(!vis[i]){
            comp.clear();
            dfs(i);
            for(int j = 0; j < sz(comp); j++){
                to[comp[j]] = j;
            }
            vt<int>d1 = bfs(0);
            int id = max_element(d1.begin(), d1.end()) - d1.begin();
            vt<int>d2 = bfs(id);
            int id2 = max_element(d2.begin(), d2.end()) - d2.begin();
            vt<int>d3 = bfs(id2);
            diam = max(diam, *max_element(d3.begin(), d3.end()));
            
            ll mn = inf, idd = -1;
            for(auto j: comp){
                
                ll val = max(d2[to[j]], d3[to[j]]);
                if(val < mn){
                    mn = val; idd = j;
                }
            }
            cand.pb(mn);
            
        }
    }
    sort(cand.rbegin(), cand.rend());
    if(sz(cand) > 1)ans = cand[0] + cand[1] + L;
    if(sz(cand) > 2)ans = max(ans, cand[1] + cand[2] + 2 * L);
    return(max(ans, diam));
}
/*
#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;
    
	FILE *f = fopen("dreaming.in", "r");
	if (!f)
		fail("Failed to open input file.");
    
	res = scanf("%d%d%d", &N, &M, &L);
	
	for (i = 0; i < M; i++)
		res = scanf("%d%d%d", &A[i], &B[i], &T[i]);
	
 
	int answer = travelTime(N, M, L, A, B, T);
	printf("%d\n", answer);
 
	return 0;
}
*/

컴파일 시 표준 에러 (stderr) 메시지

dreaming.cpp: In function 'std::vector<int> bfs(int)':
dreaming.cpp:34:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |         for(auto [v, w]: adj[comp[nw]]){
      |                  ^
dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:45:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |     for(auto [v, w]: adj[s]){
      |              ^
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:73:26: warning: variable 'idd' set but not used [-Wunused-but-set-variable]
   73 |             ll mn = inf, idd = -1;
      |                          ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...