# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42594 | Hassoony | timeismoney (balkan11_timeismoney) | C++14 | 12 ms | 2424 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include<unordered_map>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef long double D;
const ll inf=(1ll<<61);
const ll mod=1e9+7;
const int MX=209;
int n,m,vis[MX],x,y,t,c,vis1[MX][MX];
ll summoney,sumtime;
ll TIME,COST;
struct node{
int x,par;
ll time,cost;
node(){}
node(int x,ll time,ll cost,int par):x(x),time(time),cost(cost),par(par){}
};
vector<node>v[MX];
vector<int>v1[MX],v2[MX];
bool operator <(const node &A,const node &B){
return 1ll*A.cost*COST+1ll*A.time*TIME<1ll*B.cost*COST+1ll*B.time*TIME;
}
priority_queue<node>pq;
void pro(int x){
for(auto pp:v[x]){
if(vis[pp.x])continue;
pq.push(node(pp.x,pp.time,pp.cost,x));
}
}
ll l1,l2,V=inf;
int main(){
cin>>n>>m;
for(int i=0;i<m;i++){
scanf("%d%d%d%d",&x,&y,&t,&c);
v[x].push_back(node(y,t,c,0));
v[y].push_back(node(x,t,c,0));
}
for(int i=0;i<=100;i++){
for(int j=0;j<=100;j++){
TIME=i;
COST=j;
memset(vis,0,sizeof(vis));
memset(vis,0,sizeof(vis1));
for(int i=0;i<n;i++)v1[i].clear();
summoney=sumtime=0;
pro(0);
vis[0]=1;
while(!pq.empty()){
int x=pq.top().x;
ll c=pq.top().cost,t=pq.top().time,par=pq.top().par;pq.pop();
if(vis[x])continue;
vis[x]=1;
if(!vis1[x][par])
v1[x].push_back(par);
vis1[x][par]=vis1[par][x]=1;
summoney+=c;
sumtime+=t;
pro(x);
}
// cout<<sumtime<<" "<<summoney<<endl;
if(summoney*sumtime<V){
for(int i=0;i<n;i++)v2[i]=v1[i];
l1=sumtime;
l2=summoney;
V=l1*l2;
}
}
}
cout<<l1<<" "<<l2<<endl;
for(int i=0;i<n;i++){
for(auto pp:v1[i])cout<<i<<" "<<pp<<endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |