Submission #1868053


Source Code Expand

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
 
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define MAX_V 100000

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
 
using namespace std;
 
typedef pair<int,int> pii;
 
struct edge{int to;llong cost;};

vector<edge> G[MAX_V];
llong depth[MAX_V];

void dfs(int v, int par, llong d){
  depth[v] = d;
  REP(i,(int)G[v].size()){
    if(G[v][i].to == par) continue;
    dfs(G[v][i].to, v, d + G[v][i].cost);
  }
}

int main(){

  int n;
  scanf("%d", &n);

  REP(i,n-1){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a--; b--;

    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }

  int q, k;
  scanf("%d %d", &q, &k);

  k--;
  dfs(k, -1, 0);
  REP(i,q){
    int x, y;
    scanf("%d %d", &x, &y);
    x--; y--;
    printf("%lld\n", depth[x] + depth[y]);
  }
  return 0;
}

Submission Info

Submission Time
Task D - Transit Tree Path
User nena
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1572 Byte
Status AC
Exec Time 79 ms
Memory 17408 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:55:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
./Main.cpp:59:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &a, &b, &c);
                                  ^
./Main.cpp:67:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &q, &k);
                         ^
./Main.cpp:73:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &x, &y);
                           ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 31
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_1.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_2.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt
Case Name Status Exec Time Memory
sample_01.txt AC 4 ms 2688 KB
sample_02.txt AC 2 ms 2560 KB
sample_03.txt AC 2 ms 2560 KB
subtask_1_1.txt AC 2 ms 2560 KB
subtask_1_10.txt AC 18 ms 3328 KB
subtask_1_11.txt AC 2 ms 2560 KB
subtask_1_12.txt AC 4 ms 2688 KB
subtask_1_13.txt AC 7 ms 2816 KB
subtask_1_14.txt AC 2 ms 2560 KB
subtask_1_15.txt AC 4 ms 2944 KB
subtask_1_16.txt AC 78 ms 9984 KB
subtask_1_17.txt AC 78 ms 9984 KB
subtask_1_18.txt AC 78 ms 9984 KB
subtask_1_19.txt AC 79 ms 10112 KB
subtask_1_2.txt AC 3 ms 2688 KB
subtask_1_20.txt AC 73 ms 17280 KB
subtask_1_21.txt AC 73 ms 17280 KB
subtask_1_22.txt AC 73 ms 16768 KB
subtask_1_23.txt AC 72 ms 13952 KB
subtask_1_24.txt AC 63 ms 9072 KB
subtask_1_25.txt AC 63 ms 9072 KB
subtask_1_26.txt AC 63 ms 9072 KB
subtask_1_27.txt AC 63 ms 9072 KB
subtask_1_28.txt AC 70 ms 17408 KB
subtask_1_3.txt AC 53 ms 7936 KB
subtask_1_4.txt AC 2 ms 2560 KB
subtask_1_5.txt AC 25 ms 3584 KB
subtask_1_6.txt AC 9 ms 3200 KB
subtask_1_7.txt AC 21 ms 3456 KB
subtask_1_8.txt AC 2 ms 2560 KB
subtask_1_9.txt AC 54 ms 8832 KB