Submission #1039556

# Submission time Handle Problem Language Result Execution time Memory
1039556 2024-07-31T04:29:26 Z 정지훈(#11027) Petrol stations (CEOI24_stations) C++17
8 / 100
24 ms 6960 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> adj[100005];
int ind[100005];

int main(void){
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=1;i<n;i++) {
        int u,v,w;
        scanf("%d %d %d",&u,&v,&w);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int x;
    for(int i=0;i<n;i++) {
        if (adj[i].size()==1) {
            x=i;
            break;
        }
    }
    int pr=-1;
    ind[x]=0;
    for(int i=1;i<n;i++){
        for(int j=0;j<adj[x].size();j++){
            if (pr!=adj[x][j]) {
                pr=x;
                x=adj[x][j];
                break;
            }
        }
        ind[x]=i;
    }
    for(int i=0;i<n;i++){
        int now=ind[i];
long long ret=0;
        ret+=1LL*(now/k)*(n-now-1);
        ret+=1LL*((n-now-1)/k)*now;
printf("%lld\n",ret);
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for(int j=0;j<adj[x].size();j++){
      |                     ~^~~~~~~~~~~~~~
Main.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d %d %d",&u,&v,&w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp:24:11: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |     ind[x]=0;
      |     ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Incorrect 1 ms 2904 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Incorrect 1 ms 2904 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 24 ms 6960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Incorrect 1 ms 2904 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Incorrect 1 ms 2904 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Incorrect 1 ms 2904 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Incorrect 1 ms 2904 KB Output isn't correct
3 Halted 0 ms 0 KB -