Блог пользователя shailesh_2004

Автор shailesh_2004, 13 месяцев назад, По-английски

Greetings, Codeforces community!

We, Turing Hut, the official competitive programming club of VNRVJIET, Hyderabad, are thrilled to present our flagship event — Turing Cup 2K25One Team, One Dream, featuring an exciting prize pool of ₹75,000! This national-level coding contest is open to all undergraduate students.

This competition will be held in 2 Rounds.

Team Size : 1-2

Round 1 : Monday, April 7th, 2025 at 20:00 IST. This round will last for 2 hours and will be held on HackerRank(Online). The contest link will be mailed to the participants 3 hours before the commencement of the round. Shortlisted teams for round 2 will be notified via e-mail.

Round 2 : This round will be conducted on VNRVJIET Campus on Saturday, April 19th, 2025. This round will be exclusively hosted on Codeforces. Accommodation will be provided for teams based outside Telangana state.

All onsite finalists will be provided with goodies and lunch. Top prizes of Round 2 are:

Prize Distribution

Registration Link (Registration is required to be eligible for prizes)

The problems are set and tested by : Shailesh shailesh_2004 Reddy, Naveen tnaveen2308 Tummala, Adithya adithya19 Sai Ram, Srikar srikar3010 Madikuntawar, R Venkata giridhar123456 Giridhar , Soma Divya astrina Sri.

We encourage all of you to register and participate, we hope you'll like the problemset!

Happy Coding!
Turing Hut

UPD: Here are top 5 teams of the final round. Congratulations!

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Are high school students eligible for this contest?

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can someone tell me what I am doing wrong in problem D (Race for One Piece)

I am getting Terminated due to timeout for 13/206 tc; all others got accepted.

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define endl '\n'
#define ll long long
#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define srt(v) sort(v.begin(),v.end())
#define all(v) (v).begin(), (v).end()
#define yes() cout<<"YES"<<endl
#define no() cout<<"NO"<<endl
const ll mod = 1e9 + 7;
const ll N = 1e6;

ll gcd(ll a, ll b){if(b==0) return a; return gcd(b,a%b);}

int n,m;
vector<vector<pll>> old_graph;
vector<vector<pll>>graph1, graph3, graph2;
vector<int> dist, dist1, dist2, dist3;
vector<int> vis, vis1, vis2, vis3;
int st, en;
int func(int W, int X) {
    for (int i = 0; i < X; i++) {
        int S = 0;
        while (W > 0) {
            S += W % 10;
            W /= 10;
        }
        W = S;
    }
    return W;
}

/*void bfs(int sc_node){
    dist[sc_node] = 0;
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    pq.push({0,sc_node});
    while (!pq.empty())
    {
        pll node = pq.top();
        pq.pop();
        if(vis[node.S]) continue;
        vis[node.S] = 1;
        for(auto it : old_graph[node.S]){
            if(dist[it.F] > dist[node.S] + it.S){
                dist[it.F] = dist[node.S] + it.S;
                pq.push({dist[it.F], it.F});
            }
        }
    }
    
}

void bfs1(int sc_node){
    dist1[sc_node] = 0;
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    pq.push({0,sc_node});
    while (!pq.empty())
    {
        pll node = pq.top();
        pq.pop();
        if(vis1[node.S]) continue;
        vis1[node.S] = 1;
        for(auto it : graph1[node.S]){
            if(dist1[it.F] > dist1[node.S] + it.S){
                dist1[it.F] = dist1[node.S] + it.S;
                pq.push({dist1[it.F], it.F});
            }
        }
    }
    
}
void bfs2(int sc_node){
    dist2[sc_node] = 0;
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    pq.push({0,sc_node});
    while (!pq.empty())
    {
        pll node = pq.top();
        pq.pop();
        if(vis2[node.S]) continue;
        vis2[node.S] = 1;
        for(auto it : graph2[node.S]){
            if(dist2[it.F] > dist2[node.S] + it.S){
                dist2[it.F] = dist2[node.S] + it.S;
                pq.push({dist2[it.F], it.F});
            }
        }
    }
    

}*/
void bfs3(int sc_node){
    dist3[sc_node] = 0;
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    pq.push({0,sc_node});
    while (!pq.empty())
    {
        pll node = pq.top();
        pq.pop();
        if(vis3[node.S]) continue;
        vis3[node.S] = 1;
        for(auto it : graph3[node.S]){
            if(dist3[it.F] > dist3[node.S] + it.S){
                dist3[it.F] = dist3[node.S] + it.S;
                pq.push({dist3[it.F], it.F});
            }
        }
    }
    

}

int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif

    int tt; cin >> tt;
    // tt = 1;
    while (tt--) {
        cin>>n>>m;
        cin >> st >> en;
        old_graph.assign(n+1, vector<pll>(0));
        // graph1.assign(n+1, vector<pll>(0));
        // graph2.assign(n+1, vector<pll>(0));
        graph3.assign(n+1, vector<pll>(0));
        // dist.assign(n+1, 1e18);
        // vis.assign(n+1, 0);
        // dist1.assign(n+1, 1e18);
        // vis1.assign(n+1, 0);
        // dist2.assign(n+1, 1e18);
        // vis2.assign(n+1, 0);
        dist3.assign(n+1, 1.5e18);
        vis3.assign(n+1, 0);
        map<pii,int> count; 
        for (int i = 0; i < m; i++)
        {
            int a,b,c;
            cin>>a>>b>>c;
            if(a == b) continue;
            old_graph[a].pb({b,c});
            old_graph[b].pb({a,c});
            // int ans = 0;
            int temp = c;
            temp = func(temp, 1);
            count[{c, 0}] = c;
            count[{c, 1}] = temp;
            // graph1[a].pb({b, c});
            // graph1[b].pb({a, c});
            temp = c;
            temp = func(temp, 2);
            count[{c, 2}] = temp;
            // graph2[a].pb({b, c});
            // graph2[b].pb({a, c});
            temp = c;
            temp = func(temp, 3);
            graph3[a].pb({b, temp});
            graph3[b].pb({a, temp});
        }
        map<int, int> see, see1, see2, see3;
        int ans = 1.5e18;

        // see.insert({st, 0});
        for(auto [b, w] : old_graph[st]){
            int sum = 0;
            w = count[{w, 0}];
            // see1.insert({b, w});
            if(b == en) {ans = min(ans, w);
            /*cout << "b = ans : ans = " << ans << endl;*/}
            for(auto [c, w1] : old_graph[b]){
                w1 = count[{w1, 1}];
                
                if(c == en) {ans = min(ans, w + w1);
            /*cout << "c = ans : ans = " << ans << endl;*/}
                for(auto [d, w2] : old_graph[c]){
                    w2 = count[{w2, 2}];
                    sum = w1 + w2 + w;
                    // cout << b <<  " -- " << c << " -- " << d << endl;
                    // cout << "Dist : " << w + w1 + w2 << endl;
                    if(see3.find(d) != see3.end()) see3[d] = min(see3[d], sum);
                    else see3[d] = sum;

                    // see3.insert({d, w + w1 + w2});
                    if(d == en) ans = min(ans, w + w1 + w2);
                }
            }
        }
        // cout << endl;
        // for(auto &[a, b] : see){
        //     cout << a << " " << b << endl;
        // }
        // cout << "------" << endl;
        // for(auto &[a, b] : see1){
        //     cout << a << " " << b << endl;
        // }
        // cout << "------" << endl;

        // for(auto &[a, b] : see2){
        //     cout << a << " " << b << endl;
        // }
        // cout << "------" << endl;
        // for(auto &[a, b] : see3){
        //     cout << a << " " << b << endl;
        // }
        // cout << "------" << endl;
        // bfs(en);
        // bfs1(en);
        // bfs2(en);
        bfs3(en);

        // for(auto &[a, b] : see){
        //     ans = min(ans, b + dist[a]);
        // }
        // for(auto &[a, b] : see1){
        //     ans = min(ans, b + dist1[a]);
        // }
        // for(auto &[a, b] : see2){
        //     ans = min(ans, b + dist2[a]);
        // }
        // for (int i = 1; i <= n; ++i)
        // {
        //     cout << dist3[i] << " ";
        // }
        // cout << endl;
        // cout << "---------" << endl;
        for(auto &[a, b] : see3){
            if(dist3[a] < 1.5e18){
                // cout << a << " " << b + dist3[a] << endl;
                ans = min(ans, b + dist3[a]);
            }
        }
        ans >= 1.5e18 ? cout << -1 << endl : cout << ans <<endl;
        
        
    }
    return 0;
}