Submission #114313

# Submission time Handle Problem Language Result Execution time Memory
114313 2019-05-31T19:58:46 Z MohamedAhmed04 Ceste (COCI17_ceste) C++14
160 / 160
517 ms 13016 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2010 , MAXT = MAXN * MAXN;

struct edge
{
    int to , time , cost ;
    edge(int ve , int ti , int co)
    {
        to = ve ;
        time = ti ;
        cost = co ;
    }
};

vector< vector<edge> >adj(MAXN) ;
//long long dp[MAXN][MAXT] ;
long long ans[MAXN] ;
//int vis[MAXN][MAXT] ;
long long tillnow[MAXN] ;

int n , m ;

int readint()
{
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch-'0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result*10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}

int main()
{
    n = readint() ;
    m = readint() ;
    int a , b , c , d ;
    int Max = 0 ;
    for(int i = 0 ; i < m ; ++i)
    {
        a = readint() ;
        b = readint() ;
        c = readint() ;
        d = readint() ;
        Max = max(Max , c) ;
        adj[a].push_back(edge(b , c , d)) ;
        adj[b].push_back(edge(a , c , d)) ;
    }
    long long cons = 1e17 ;
    for(int i = 1 ; i <= n ; ++i)
        ans[i] = cons , tillnow[i] = 1e17;
    //dijkstra
    priority_queue< pair<int , pair<int , int> > , vector< pair<int , pair<int , int>  > > , greater< pair<int , pair<int , int> > > >q ;
    q.push({0 , {0 , 1}}) ;
    bool flag = 0 ;
    while(!q.empty())
    {
        pair<int , pair<int , int> >p = q.top() ;
        q.pop() ;
        int node = p.second.second , sumc = p.first , sumt = p.second.first ;
        ans[node] = min(ans[node] , (sumt * 1ll) * (sumc * 1ll)) ;
        if(sumt > tillnow[node])
            continue;
        tillnow[node] = sumt ;
        for(auto &child : adj[node])
        {
            int nto = child.to ;
            int ntime = child.time + sumt;
            int ncost = child.cost + sumc;
            if(ntime >= MAXT)
                continue ;
            q.push({ncost , {ntime , nto}}) ;
        }
    }
    for(int i = 2 ; i <= n ; ++i)
    {
        if(ans[i] == cons)
            ans[i] = -1 ;
        printf("%lld\n" , ans[i]);
    }
    return 0 ;
}

Compilation message

ceste.cpp: In function 'int main()':
ceste.cpp:71:10: warning: unused variable 'flag' [-Wunused-variable]
     bool flag = 0 ;
          ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1148 KB Output is correct
2 Correct 55 ms 2168 KB Output is correct
3 Correct 71 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 2160 KB Output is correct
2 Correct 517 ms 13016 KB Output is correct
3 Correct 8 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 952 KB Output is correct
2 Correct 321 ms 6764 KB Output is correct
3 Correct 13 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 220 ms 1140 KB Output is correct
2 Correct 219 ms 2160 KB Output is correct
3 Correct 201 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 2160 KB Output is correct
2 Correct 177 ms 2132 KB Output is correct
3 Correct 275 ms 2228 KB Output is correct