Submission #114294

# Submission time Handle Problem Language Result Execution time Memory
114294 2019-05-31T18:05:49 Z MohamedAhmed04 Ceste (COCI17_ceste) C++14
48 / 160
2500 ms 636 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAX = 2010 ;
 
struct edge
{
    int to , time , cost ;
    edge(int ve , int ti , int co)
    {
        to = ve ;
        time = ti ;
        cost = co ;
    }
};
 
vector< vector<edge> >adj(MAX) ;
int vis[MAX] ;
int n , m ;
 
long long ans[MAX] ;
 
void dfs(int node , int sumt , int sumc)
{
    //trying a thing.
    long long now = (sumt * 1ll) * (sumc * 1ll) ;
    if(now > ans[node] * 8ll)
        return ;
    ans[node] = min(ans[node] , now) ;
    for(auto &child : adj[node])
    {
        if(vis[child.to] == 1)
            continue ;
        vis[child.to] = 1 ;
        dfs(child.to , sumt + child.time , sumc + child.cost) ;
        vis[child.to] = 0 ;
    }
    return ;
}
 
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 ;
    for(int i = 0 ; i < m ; ++i)
    {
        a = readint() ;
        b = readint() ;
        c = readint() ;
        d = readint() ;
        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 ;
    dfs(1 , 0 , 0) ;
    for(int i = 2 ; i <= n ; ++i)
    {
        if(ans[i] == cons)
            ans[i] = -1 ;
        printf("%lld\n" , ans[i]);
    }
    return 0 ;
}
# 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 Execution timed out 2533 ms 384 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2527 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2542 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2542 ms 588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2554 ms 636 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2546 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2561 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -